ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable Range & Sorting Macro (https://www.excelbanter.com/excel-programming/428230-variable-range-sorting-macro.html)

David127

Variable Range & Sorting Macro
 
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






Jacob Skaria

Variable Range & Sorting Macro
 
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
---------------
Jacob Skaria


"David127" wrote:

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






Don Guillett

Variable Range & Sorting Macro
 
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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"David127" wrote in message
...
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








All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com