Button to select range based on the first/last cell content

m.hamadeh

New Member
Joined
Jun 14, 2011
Messages
32
Dear Experts,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I would like to ask for a VB for a button to perform automatic range selection based on the content of the first cell and the last cell, as example:
<o:p> </o:p>
The first cell is fixed at A1 lets assume A1=”PIDSTART” and below at dynamic location another cell contain “PIDEND”. The macro shall search for this cell and select the range from A1 to the cell with “PIDEND” value.
<o:p> </o:p>
Example the range that will be selected A1:U23
<o:p> </o:p>
Best regards,
<o:p> </o:p>
m.hamadeh
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this

Code:
Sub test()
Dim Found As Range
Set Found = Cells.Find(what:="PIDEND", LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Range(Range("A1"), Found).Select
End Sub
 
Upvote 0
Try this

Code:
Sub test()
Dim Found As Range
With Sheets("Sheet2")
    Set Found = .Cells.Find(what:="PIDEND", LookIn:=xlValues, lookat:=xlWhole)
    If Not Found Is Nothing Then Application.Goto .Range(.Range("A1"), Found)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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