PDA

View Full Version : [Beginner] Select and Cut with conditions



Telemedium
04-19-2020, 06:10 PM
Hello I have the following problem : I want a macro that run line by line to check if the value of a cell is a certain something, if it is, the macro should select the next 5 cells in a line and move them right by 1 cell.

For now I have the following code but it won't work:

Sub Movestuff()
'
' Movestuff Macro
'
Dim cell As String
For Each cell.Value In Columns("C:C")
If cell.Value = "OU=" Then
Range("C:G").Select
Selection.Cut Destination:=Range("D:H")

End If

Next cell
End Sub

paulked
04-19-2020, 06:25 PM
Hi and welcome to the forum

try:



Sub Shft()
Dim lr As Long, i As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 3).End(xlUp).Row
For i = 1 To lr
If Cells(i, 3) = "OU=" Then
Range("C" & i & ":G" & i).Cut Range("D" & i)
End If
Next
End Sub