VBA LastRow to Specific Text

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is it possible to set a range in a column so it's set from last row to specific text found (header) but doesn't include the header.

Example 1 - Sets the range so only the 2 rows found (Nothing,Something)
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Specific Text[/TD]
[/TR]
[TR]
[TD]Nothing[/TD]
[/TR]
[TR]
[TD]Something[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Example 2 - Sets the range so only the 6 rows found (Something,Something,Something,Something,Nothing,Nothing)

[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Specific Text[/TD]
[/TR]
[TR]
[TD]Something[/TD]
[/TR]
[TR]
[TD]Something[/TD]
[/TR]
[TR]
[TD]Something[/TD]
[/TR]
[TR]
[TD]Something[/TD]
[/TR]
[TR]
[TD]Nothing[/TD]
[/TR]
[TR]
[TD]Nothing[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Yes I now realise A1 is the start point, I have a few words that I need finding so is it possible to pass it to an array?
The words I am trying to find are "Temp", "Permanent", "Part Time", "Full Time" and "Flexi-time"
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try
Code:
Sub GetRng()

    Dim Ary As Variant
    Dim Cnt As Long
    Dim Fnd As Range
    Dim Rng As Range
    
    Ary = Array("[COLOR=#ff0000]Sold By[/COLOR]", "[COLOR=#ff0000]Sold On[/COLOR]", "[COLOR=#ff0000]Qty[/COLOR]")
    For Cnt = LBound(Ary) To UBound(Ary)
        Set Fnd = Cells.Find(Ary(Cnt), Range("A1"), xlValues, xlWhole, xlByRows, xlNext, False, False)
        If Not Fnd Is Nothing Then
            Set Rng = Range(Fnd.Offset(1), Cells(Rows.Count, Fnd.Column).End(xlUp))
        End If
        Rng.Select
        ' do something?
    Next Cnt
    
End Sub
Replacing values in red to match your criteria
 
Upvote 0
This is Perfect, Thank you Fluff and njimack for taking time to help me. It's much appreciated
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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