Variable Range & Sorting Macro

D

David127

I'm new to VBA & need to create a macro that can find the row with "Lou" &
move that row to the top of the data table. The hitch is the data table
postion & the number of rows vary from day to day. The example table below
Lou is in row 27 but he could be in row 14 or any other row. The data table
is contigous but my start on row 1 or row 5.

Thanks in advance!
David


Ca Cb Cc Cd Ce
R1 Joe j k l a
R2 Sue d f e c
R... x x x x
R27 Lou i w z o
 
J

Jacob Skaria

Try this and feedback

Sub Macro()
Dim lngRow As Long
Dim lngLastRow As Long
Dim varTemp
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

For lngRow = 1 To lngLastRow
If UCase(Range("A" & lngRow)) = "LOU" Then
varTemp = Range("A" & lngRow & ":Z" & lngRow)
Rows(lngRow).Delete
Rows(1).Insert
Range("A1:Z1") = varTemp
End If
Next

End Sub


If this post helps click Yes
 
D

Don Guillett

Sub MoveNameToTopRow()
myname = InputBox("Enter name to move")
Rows(Columns("a").Find(What:=myname, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Row).Cut
Rows(2).Insert
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top