xlToRight Issue

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
205
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,767
Office Version
2007
Platform
Windows
Try this

Code:
Range(Cells(lr, 6), Cells(lr, Columns.Count).End(xlToLeft)).Select
 

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
205
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!
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,767
Office Version
2007
Platform
Windows
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,767
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,081,727
Messages
5,360,913
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top