xlToRight Issue

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
247
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm using the following code to find the end of a range but the problem I'm having is that range (the xlToRight) can change. Is there a way to instead have this select all the way to the right until it runs into a certain value? For example, if I have the word "END" in column T it would do the xlToRight all the way until Column T regardless if there were values between Column F (the "6" in the Cell function) and Column T?

Range(Cells(LR, 6), Cells(LR, 6).End(xlToRight)).Select
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this

Code:
Range(Cells(lr, 6), Cells(lr, Columns.Count).End(xlToLeft)).Select
 
Upvote 0
Thanks... the only issue with this approach is I have another set of data adjacent to the first set so this code will now cross both sets of data rather than just the first... hope that makes sense!
 
Upvote 0
Try this


Code:
Set b = Rows(lr).Find("[COLOR=#ff0000]End[/COLOR]", LookIn:=xlValues, lookat:=xlWhole)
If Not b Is Nothing Then
    Range(Cells(lr, 6), Cells(lr, b.Column)).Select
Else
    Range(Cells(lr, 6), Cells(lr, 6)).Select
End If
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top