Selecting multiple cells in column until specific value

cgorry

New Member
Joined
Sep 7, 2006
Messages
2
Hi all,
I'm trying to create a simple macro that will select multiple cells that are adjacent in a column.

This will be used on several worksheets, and some contain a number of blanks that I want to include.

The list will always begin in say A1, but each will be of differing lengths. I imagined having an "END" or similar value at the very bottom of each list and perform multiple ctrl+shift+down until End is reached, the loop will stop and a copy paste will be carried out and the macro will end.

I realise that this is straightforward but am quite a novice!
Thanks,
Chris
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,962
Office Version
  1. 365
Platform
  1. Windows
Do you mean something like this?

Range(Range("A1"), Range("A1").End(xlDown)).Select

This code will start in cell A1 and go down column A until it finds the first blank, then select that whole range.
 

cgorry

New Member
Joined
Sep 7, 2006
Messages
2
Hi there,
Close but not quite!

The list will always start in cell A1, and need to select cells starting there going down the column (including blank cells) until a specific value is found (such as END etc).

Thanks again
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,962
Office Version
  1. 365
Platform
  1. Windows
Try something like this:
Code:
Sub MyHighlightRange()
    
    Dim myValue As String
    
'   Enter value to look for
    myValue = "end"
    
'   Find value in column A
    Columns("A").Find(What:=myValue, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate
    
'   Highlight range
    Range(Range("A1"), ActiveCell).Select
    
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,697
Messages
5,855,226
Members
431,712
Latest member
Stella J

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
Top