Forum Discussion

renee_crozier's avatar
renee_crozier
Copper Contributor
Apr 17, 2024

Find, Select Row, and Select up to Row 1 Using VBA Code

Using VBA code, I'm looking to use the Find and Replace dialogue box, find a certain item, select the entire row of data, and then select all the way up to row 1 and then copy it.

 

For this, I am using Excel 2016 (preferred) but I have access to 365 if it is not possible in 2016.

 

The VBA code that I have now is

 

Cells.Find(What:=":", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate

 

 

  • renee_crozier 

    The following does not select the range, but it does copy it, ready to be pasted elsewhere:

        Dim rng As Range
        Set rng = Cells.Find(What:=":", After:=ActiveCell, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
        Range(Range("A1"), rng).EntireRow.Copy
  • renee_crozier 

    The following does not select the range, but it does copy it, ready to be pasted elsewhere:

        Dim rng As Range
        Set rng = Cells.Find(What:=":", After:=ActiveCell, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False)
        Range(Range("A1"), rng).EntireRow.Copy

Resources