xlToRight Issue

happyhungarian

Active Member
Joined
Jul 19, 2011
Messages
254
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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