OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 439
- Office Version
- 2019
- Platform
- Windows
Hello and thanks in advance to all those who attempt to assist and I will post a response on feedback to proposed solutions.
I have a large data set which consists of more than 200,000 rows. I am searching column R to see if has total in it. If it does, I select it and all the cells within that row to the right of it up until the last cell (last column). I then cut it, and past it in the row below it starting in column A. Since there is data already in Columns A through Q all the way up to the last row of the spreadsheet, I have to insert the cut data. When I run the following code, nothing happens. Any insight on why?
Once again thanks!
I have a large data set which consists of more than 200,000 rows. I am searching column R to see if has total in it. If it does, I select it and all the cells within that row to the right of it up until the last cell (last column). I then cut it, and past it in the row below it starting in column A. Since there is data already in Columns A through Q all the way up to the last row of the spreadsheet, I have to insert the cut data. When I run the following code, nothing happens. Any insight on why?
Code:
Sub Total()
'Activate the sheet
Worksheets("Data.Raw").Activate
'Find the last row.
Dim LastRow As Long
LastRow = Cells.Find(What:="*", _
after:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
'Find the last column.
Dim LastColumn As Long
LastColumn = Cells.Find(What:="*", _
after:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
'Move Total Line within the Data Set
Dim i As Long
For i = LastRow To 1 Step -1
If LCase(Cells(i, 18).Value) = "Total" Then
Range("R" & i, LastColumn).Cut
Range("A" & i + 1).Insert xlShiftDown
End If
Next i
End Sub
Once again thanks!