HappyLadyToo
Board Regular
- Joined
- Aug 28, 2012
- Messages
- 64
Hi!
I'm trying to use an old macro on a new worksheet but I'm hoping someone can help with the differences. Originally this macro was used to move rows based on an empty cell in a column. Now I'd like to use it to move rows based on a value in a column. The only thing I can think to do is to hard code each values into the macro but the values can change each month. I was considering recording a macro for some of the steps but again, the macro becomes hard coded.
The end result should be each row with the value in column G (in this case a name) should be moved to a new worksheet with that name on the tab.
Please ask if you need clarification.
I'm trying to use an old macro on a new worksheet but I'm hoping someone can help with the differences. Originally this macro was used to move rows based on an empty cell in a column. Now I'd like to use it to move rows based on a value in a column. The only thing I can think to do is to hard code each values into the macro but the values can change each month. I was considering recording a macro for some of the steps but again, the macro becomes hard coded.
The end result should be each row with the value in column G (in this case a name) should be moved to a new worksheet with that name on the tab.
Please ask if you need clarification.
Code:
Option Explicit
Sub moveblank()
Dim wsCopy As Worksheet
Dim wsPaste As Worksheet
Set wsCopy = ThisWorkbook.Sheets("Buyer_Summary")
Set wsPaste = ThisWorkbook.Sheets("Sheet2")
Dim lBottomrow As Long
lBottomrow = wsCopy.Range("A" & wsCopy.Rows.Count).End(xlUp).Row
Dim rCopy As Range
Dim rDelete As Range
Dim c As Range
Set rCopy = wsCopy.Range("G1:G" & lBottomrow)
For Each c In rCopy.Cells
If c = "Joe" Then
If rDelete Is Nothing Then
Set rDelete = c.EntireRow
Else
Set rDelete = Union(rDelete, c.EntireRow)
End If
End If
Next c
rDelete.Copy
lBottomrow = wsPaste.Range("A" & wsPaste.Rows.Count).End(xlUp).Row
wsPaste.Range("A" & lBottomrow).EntireRow.PasteSpecial (xlPasteAll)
rDelete.Delete
End Sub
Last edited by a moderator: