TryingBest
New Member
- Joined
- Aug 2, 2022
- Messages
- 30
- Office Version
- 2016
- Platform
- Windows
Hi,
I am new to this amazing forum where great help is offered.
I wanted to move an entire row at the bottom of the page based on a specific word/criteria match in a column. I found this piece of code and implemented it, which works great.
But, running into an issue, if the word is not matched it gives a debug error - rather than moving on to the next search item in the list.
I am very much new to this coding/VBA, so asking for help. Code is pasted below.
If 'abc' is not in column C, it gives an error and not moving on to the next item 'xyz'
I am new to this amazing forum where great help is offered.
I wanted to move an entire row at the bottom of the page based on a specific word/criteria match in a column. I found this piece of code and implemented it, which works great.
But, running into an issue, if the word is not matched it gives a debug error - rather than moving on to the next search item in the list.
I am very much new to this coding/VBA, so asking for help. Code is pasted below.
If 'abc' is not in column C, it gives an error and not moving on to the next item 'xyz'
VBA Code:
Sub MoveRows()
Dim rng As Range
With Range("C:C")
.Replace "abc", "=Xabx", xlWhole, , False, , False, False
Set rng = .SpecialCells(xlFormulas, xlErrors)
.Replace "=Xabc", "abc", xlWhole, , False, , False, False
rng.EntireRow.Copy Range("A" & Rows.Count).End(xlUp).Offset(2)
rng.EntireRow.Delete
End With
With Range("C:C")
.Replace "xyz", "=Xxyz", xlWhole, , False, , False, False
Set rng = .SpecialCells(xlFormulas, xlErrors)
.Replace "=Xxyz", "xyz", xlWhole, , False, , False, False
rng.EntireRow.Copy Range("A" & Rows.Count).End(xlUp).Offset(2)
rng.EntireRow.Delete
End With
End Sub