Select Range Using Offset With Variables

Apr 23, 2008

I am trying to select a range in VBA, where I know the name of the starting cell, and the size of the range are values returned earlier in the VBA function. I guess the pseudocode I am trying to do is: range(range("StartCell"):range("StartCell").Offset(x,y)).Select. Obviously this code doesn't work, but I don't know the correct way to select this range

View 2 Replies


ADVERTISEMENT

VBA Select Range To Copy Based On Two Variables

Jan 13, 2014

I have a Macro that already works great but now I need to look for another variable to sort it down even further. I think it can be done by setting up a "Case" but still not sure how to do that. It already looks through the range to find all the rows that return a value of "True". Now I need it sort those results so it only returns what has a specified value in Column "AJ". I am looking to do several choices (Listed Here). So the end result will be all the items that return "TRUE" In Column "AI" and are Items that return one of these values per Case "Starters, Appetizers, Soup, Salad, Entree, Dessert, Special" with then copy over in the exact format that is listed in the code below.

For example All the items that are selected with "TRUE" can be narrowed down to all of those that are "Salad" as well - Then copied over in the exact format that is listed in the code below.

What I am doing is breaking out all the different course of food and putting a Header in-between each (That is already built and working) - So I can select all the food from a master list and then put it in order on the "Catering BEO" Sheet with Headers in between

Code:
Sub BEOA4()
Application.ScreenUpdating = False
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim FoundX As Range
Dim FirstFound As String
Dim lastrow As Long

[code]....

View 3 Replies View Related

Offset And CountA To Auto Select Data Range For Charting Purposes?

Dec 12, 2013

how to play with data ranges and define names for charts to automatically update them by using the formula offset + counta. An example would be: =OFFSET(Sheet1!$B$7,0,0,COUNTA(Sheet1!$B$6:$B$37)-1).

So, the problem comes when there is a need to select a data range which is not that well defined like $B$6:$B$37. So, I need to import data regularly into my workbook, this data will be imported right below of the last cell with values.

Now, how would I manage to automatically select the data range from this new import for my chart? See attached example. I have highlighted in Yellow a potential import... there is no data in there so feel freel to fill it with any numbers you like.

I have tried to use a vlookup to find Country+Programme+Year (cat1 in the example) in the 'counta' part of the formula above. But I get lost,as a vlookup would retrieve a value and would not be useful for the data range?

View 8 Replies View Related

Merge Cells: Select A Range Based On Two Variables Which Store The Column Numbers

Jul 19, 2009

I am trying to select a range based on two variables which store the column numbers. what I have is:

View 4 Replies View Related

Macro To Find A Cell Containing Text /select Range Offset / Cut And Paste To Lower Rows?

Feb 4, 2014

I am trying to find a macro that can search a sheet for any cell that contains the text "Not on AOI" selects a range that contains that cell, 81 rows below, and 2000 columns to the right, then cuts the selection and pastes it 162 rows below the original cell where the text was found. What's hard is that the number of columns between the "Not on AOI" cells is variable.

I'm very new to excel macros and the parts I think I've put together are:

Cells.Find("Not on AOI", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=True).Activate

[Code].....

View 1 Replies View Related

OFFSET With Variables

May 15, 2009

I am trying to OFFSET from cell A1 based upon a variable in cell A2. The cell I need to OFFSET to is also located in column A, but it could always differ based upon the variable in A2. Here is the piece of code performing this OFFSET.

View 7 Replies View Related

Using Currentcell.offset To Copy A Cell From Two Variables

Mar 5, 2010

I have a spreadsheet with 2 worksheets. I have a variable cell and a display cell on Worksheet A and two other cells with information on Worksheet B that I need copied over to Worksheet A based on what is entered for the variable on Worksheet A.

I want to be able to enter a variable in Worksheet A, cell B25. I then want the code to look up the variable I just entered at B25 on Worksheet B, column A. Once the code finds the variable, then I want the code to copy what is in column B and enter it into Worksheet A cell C25.

In other terms, I want to enter "Bob" in Worsheet A, B25. On Worksheet B, I have 50 different names of people in column A and additional info directly to the right of their names in column B. When I enter "Bob", I want the code to find "Bob" on the Worksheet B and enter "is worthless" on Worksheet A, cell C25.

I have tried and got the code to work with several If/then statements and I accomplished the same using a select case arguement as well using something along the lines of "if B25="Bob" then C25=worksheet B("B2")" assuming Bob is in cell A2. My concern is the info on Worksheet B is fluid. I need to be able to sort and add additional lines at any given time. My data set is going to be between 500 and 800 rows. Any time I add a row and re-sort the data set, I want the code to find "Bob" in column A and then display what is in column B in Worksheet A, C25. I can continue to use the if/then statements, but they are static and if I add a new row near the top, I would have to re-number all the if/then statments in the code.

View 9 Replies View Related

Select The Cell Via VBA / Offset

Nov 16, 2007

The Sheet below is an example of what I need to fill in daily

In column B I have the week commencing date (ie the Monday)

When the sheet is opened, I want the approriate day to be selected (ie the day before the current day)

Eg. if today is Friday 16th November, when the sheet is opened I want the cell for Sales on Thursday of the week which begins with 12/11/07 to be selected ie L5

If today is Monday 26th November i want Sales on Sunday of the week which begins with 19/11/07 to be selected ie U6 ....

View 9 Replies View Related

Target.offset To Select Ranges

Mar 27, 2007

i'm having a really hard time figuring out how to use target. offset to grab a range of cells. For Example:

I am currently running a macro that searches column "D:D" for data. When the data is found, i want to be able to Grab columns D to AG for that row, and apply conditional formatting. It seems like using Target.Offset should be able to accomplish this, but i can't figure out how to specify a range using Target.Offset. Currently, i have to specify each cell i'd like to select, and apply formatting one at a time, which has bloated my code considerably (and causes me to run out of room very quickly).

View 4 Replies View Related

VBA - Find Select Offset Copy And Paste

Aug 23, 2012

I am trying to achieve something like this :

Find a specific text in my column B (example : "Proposal ID"), when "Proposal ID" is found, select this cell and offset to the column C (Offset(0, 1)). Then copy this cell value in another sheet.

This will be repeated with different texts (always in the column B), so if the text is not found, I need the macro to continue running.

View 5 Replies View Related

Select An Excel Sheet With 2 Variables In It?

May 17, 2013

So far my line of code is:

Sheets(" & Cstr(y) & " - " & Cstr(i) & " load" & ").Select"

Selecting a worksheet with 2 variables in it and some text,where y and i are integer variables. P

View 1 Replies View Related

Range.select Error (SELECT METHOD OR RANGE CLASS FAILED)

Jul 23, 2008

I have this:

Private Sub CommandButton1_Click()
Worksheets("Sheet1").Activate
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
ActiveCell.PasteSpecial
End Sub
it errors to: SELECT METHOD OR RANGE CLASS FAILED

View 9 Replies View Related

Select Last Non-blank Row And Offset To Next Cell Type A Message In It

Oct 2, 2013

I am trying to achieve the below objective but getting error message

Objective: select last non blank row and offset to next cell type a message in it
error message: Runtime error 1004 : method 'Range' of Object '_Global' Failed

CODE:

Sub lastRowAll()
myvar = ActiveSheet.UsedRange.SpecialCells(11).Column
myrow = ActiveSheet.UsedRange.SpecialCells(11).Row
Range(myvar, myrow).Offset(0, 1).Value = "Experiments with VBA"
Range(myvar, myrow).Offset(0, 1).Activate
End Sub

View 6 Replies View Related

Select Non Contiguous Ranges Via Macro, Using Variables

Apr 29, 2008

trying to select multiple ranges of data at once using variables as my selection range criteria.

I.e., I want something similar to:

Range("A10:A30,B10:B30,E10:E30").Select

But would like to be able to perform the same selection using variables.

StartVar = 10, EndVar = 30

I'm sure it's just a matter of syntax, but I can't seem to get it right.

View 3 Replies View Related

Automatically Select From Dropdown Based On Variables In 2 Other Cells

Jan 6, 2013

I have a sheet where I have a "Status" column in each row which could be "Waiting for Band", "Waiting for Organizer", or "Ready to Go!". These options are set as a data validation list. I have 2 cells later in each row where the response can only be "Yes" or "No". I want for the Status column to be set automatically based on the responses in the later two cells. So for example

where C3 and M3 are Yes, the status column in B3 should read "Ready to Go!"
where C3 is no but M3 is yes, the status column should read "Waiting for Organizer"
where C3 is no and M3 is no, the status column should read "Waiting for Band"

The above is actually an exhaustive list of all of the potential outcomes(!)

View 4 Replies View Related

Range Select Statement To Select A Cell

Jul 7, 2008

I want to put a range select statement to select a cell and count down 10 cells and copy.

View 9 Replies View Related

If Select Sheet, Select Range Statement

Oct 4, 2007

I have a command button on sheet MASTER. When the workbook is Activated I want it to check and see if in sheet COSTM, cell B3 there are the words "Project Number", if so then show command button (ClearPrevious), if not, don't show. Also, when the If statement is finished, then the workbook needs to end up showing the sheet MASTER. I have tried various codes and none work, or they are on perpetual loops. I know this has got to be simple, but cannot find an example to take from to solve the issue. Would appreciate any help offered. Below is code I have right now.

Private Sub Worksheet_Activate()
If Sheets("COSTM").Select Range("B3").Select = "Project Name:" Then
Me.ClearPrevious.Visible = True
Else
Me.ClearPrevious.Visible = False
End If
Sheets("MASTER").Select
End Sub

View 9 Replies View Related

Set Range And Offset

May 16, 2009

I am having trouble with one line of this code that I can't figure out how to write correctly. I have set the range, but I need to offset by 10 rows up. My code fails at set rng.

View 6 Replies View Related

Offset Range Value VBA

Sep 29, 2009

I have an offset range ("TheCell") that does not seem be working how I would expect.

I don't know if its because the sheet I am working on was originaly German but I would be surprised if that was the case.

I Use sheet change to set the peramiters of the range and to test the value

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rowcell
Dim colcell
Dim typeit
colcell = ActiveCell.Column
rowcell = ActiveCell.Row
ActiveWorkbook.Names.Add Name:="iname", RefersToR1C1:="=" & "Tabelle2!R1C" & colcell
ActiveWorkbook.Names.Add Name:="Jname", RefersToR1C1:="=" & "Tabelle2!R" & rowcell & "C2"
typeit = Range("TheCell").Value
MsgBox typeit
End Sub
=OFFSET(Tabelle1!$B$4,MATCH(Jname,Tabelle1!$B$5:$B$57,0),MATCH(iname,Tabelle1!$B$4:$EX$4,0)-1)

but for some reason I am getting a runtime error 1004 worksheet failed.

I have used this technique before and its been fine so what mistake have I made :o)

View 9 Replies View Related

Range Offset

Aug 24, 2006

I want to apply some logic to a range. However I want to offset the bottom of the range by 1 row.

Example: I have a range (B8:I19) already defined in my vba code. But I want to shade range (B8:I20).

MyRange = Range("B8:B19")
MyRange.Offset(1, 0).Interior.ColorIndex=3

This code also offsets the top of the range (row 9), which I don't want.

How can I only offest the bottom of the range?

View 5 Replies View Related

Copying An Offset Range

Aug 29, 2008

I would like to work with a range of cells.

I have a headerCel (A2)and a footerCel (A20).

If I use the line

View 9 Replies View Related

Range.Offset Limit

Dec 8, 2008

I am currently writing some VBA code to loop through and copy data from Excel file in sub folders into a master sheet of data. There are some 1200 Excel files (these are pre-2007 files), each containing a maximum of 600 lines of data. So far the code works until it gets to around 65000 rows (the old Excel limit). I am using and writing the code in a Macro-Enabled Excel 2007 file.

I am using a Range.Offset call, which is where the error is occurring, to copy in a name basically. What happened right before this was a Range.Copy operation from the old Excel file to a Range.PastSpecial in the new one. This worked fine, and actually went a few hundred rows past the pre-Excel 2007 limit. But when the single cell operation Range.Offset().Value is called next, it crashes with a Application or User-Defined error. The code works some 100+ times through the loop with no problem, and the file that it was working on is no different then the other files.

View 9 Replies View Related

Go Down Range, Then Cut, Offset, Paste

Jan 28, 2009

I am trying to create a macro that goes down Column A of my sheet and looks for a string, "Number". When it finds it, it resize (0, 14) and cuts. Then it pastes the array at an offset of (-1, 10) This is what I got so far:

View 4 Replies View Related

Copy A Range, Then Specified By An Offset

Mar 10, 2009

I'm trying to copy a range, specified by an offset, then PasteSpecial that range to yet another location specified by an offset.

This is the code I have so far, which does not attempt to find the range to copy via an offset.

View 5 Replies View Related

Activate Range By Offset

Oct 11, 2011

How do I activate four cells to the right of A5 using the offset function. I will need this to operate indivitually for each row so I cant use Range("B5:E5").Select. All I want to do is to merge the four cells to the right of column A

View 6 Replies View Related

Offset Range Of Cells?

Feb 7, 2013

How do I offset a range of cells?

I'm running simulations. Let's say I want to run the "for" loop 100 times. In the 1st iteration I want to copy Range(A1:A10) and paste the value to A31:A40 (this destination range is fixed for each iteration). In the 2nd iteration I want to copy Range(B1:B10) and paste to (or assign value to) A31:A40. In the 3rd iteration I want to copy Range(C1:C10) and paste to (or assign value to) A31:A40. And so on for 100 iteration. So each time my copied range moves one column to the right.

How do I achieve this in VBA code? Let's say I have defined/named Range("A1") and want to keep offsetting to the right but copying 10 cells in the range as I go along.

View 6 Replies View Related

Offset Range Naming

Jun 15, 2006

= OFFSET(CustomerInfo!$A$9,0,0, COUNTA(CustomerInfo!A:A),1)

for a "dynamic" range name...i like the concept, but my data validation in a cell that references this "dynamic" range name (with the offset function) doesn't recognize all the values in the range

(when i just range name it, the data validation sees all the names, but not all when i use the offset...)

View 5 Replies View Related

Offset X Rows Of Last Row In Range

Jan 3, 2008

given a range named xyz which refers to d1:e3

range("xyz")

where the 3rd row is blank. I want to examine the row after the range with

range("xyz").end(xlUp).Offset(1,0).Cells(1,1).value

I find that this code refers to the last row of the range which is blank. How can I be sure that I will be 1 row (offset=1) below the range?

View 2 Replies View Related

Use Variables In A Range?

Aug 23, 2009

I used a macro to get the following code, but would like to do this with VBA code where I use variables and numbers instead of the
macro's ("I568:J568") notation. Thus I would have something like (lRow, 9) : (lRow, 10) or whatever the correct notation is. Basically I'm trying to copy and paste formulas from one row to the next.

View 4 Replies View Related

Using Variables To Set Sum Range

Dec 30, 2013

I am trying to sum the range of column B (Being the found match in column A offset 1) to the relevant column set by the variable intcolumn (integer value of the column matching the criteria (in this case column 25)

Code:
rngMember.Offset(0, 13) = Application.Sum(rngTradeMember.Offset(0, 1) & ":" & rngTradeMember.Offset(0, intColumn))

The sum does not fail but returns an incorrect figure.

What I am hoping to see is a sum of the following

result sheet offset (0,13) = sum of (column B to the column Y)

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved