Forum Discussion
renee_crozier
Apr 17, 2024Copper Contributor
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
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
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