jfrank85
asked on
set range up until text vba help
for some reason my range isn't working right.
'set new range
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang e("B4"), 6)) - 1)
on worksheet B4, it lists: "Week9", this may change, and I want to set my range from A1 up until that text of the B4 on worksheet "RUN". How can I get this to work properly?
Thanks.
'set new range
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang
on worksheet B4, it lists: "Week9", this may change, and I want to set my range from A1 up until that text of the B4 on worksheet "RUN". How can I get this to work properly?
Thanks.
Hi,
pls try
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang e("B4"), 5, 2)) - 1)
you had 6 when Week9 has only 5 letters
Regards
pls try
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang
you had 6 when Week9 has only 5 letters
Regards
Do you mean you want to set the range from A1 to the cell in column A that has the text that is in B4?
Do you want to include the "RUN" row or the row before that?
aikimark
Isn't 'RUN' the name of the worksheet?
Isn't 'RUN' the name of the worksheet?
@Norie
It wasn't clear whether the text was missing an equals sign
...or if the row needed to be the last row containing the text value of cell B4
...or whether we sought the last non-empty row in column B.
It would be a more clearly defined problem if we had a representative sample workbook.
It wasn't clear whether the text was missing an equals sign
...until that text of the B4 on worksheet = "RUN"
...or if the row needed to be the last row containing the text value of cell B4
...or whether we sought the last non-empty row in column B.
It would be a more clearly defined problem if we had a representative sample workbook.
ASKER
To be clear:
the worksheet "RUN" will list the Week name in B4. This week name is in the format of: "Week #".
It can be anywhere from "Week 1" to "Week 52".
Throughout the rest of the workbook are other tabs, which are created by my macro. I'm currently using this code to grab the range:
'set new range
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang e("B4"), 6)) + 3)
However, I notice that if I have "Week 9" in B4 on the Run worksheet, my range actually captures up to "Week 10". So something is off here..
On the other tabs, to be clear, the weeks are in the title bar, so A1:BF1
the worksheet "RUN" will list the Week name in B4. This week name is in the format of: "Week #".
It can be anywhere from "Week 1" to "Week 52".
Throughout the rest of the workbook are other tabs, which are created by my macro. I'm currently using this code to grab the range:
'set new range
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("A1").Resize(lr, Val(Mid(Worksheets(1).Rang
However, I notice that if I have "Week 9" in B4 on the Run worksheet, my range actually captures up to "Week 10". So something is off here..
On the other tabs, to be clear, the weeks are in the title bar, so A1:BF1
Assuming you want to start at A1 and go down as far as the first instance of the text specified in B4, you can use the MATCH function:
=MATCH($B$4,Run!$A:$A,0)
The VBA equivalent may have to use the "Application.WorkbookFunct ion" statement but will generate a variable value which can then be used as the last row of the range.
Thanks
Rob H
=MATCH($B$4,Run!$A:$A,0)
The VBA equivalent may have to use the "Application.WorkbookFunct
Thanks
Rob H
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Norie! works great
Open in new window
Saurabh...