Using Loop

Private Sub CommandButton1_Click()

If (Range(“D35”).Value) <> Range(“D6”).Value   Then
    Range(“E35:AQ35”).Cut Range(“D35:AP35”)
   
    Application.CutCopyMode = False

End If
End Sub

 

The above vba is for the cell “D35”, but I want the to use the same formula for all the cells from column D to column AQ for row 35.

For example for column E the code would be:

Private Sub CommandButton1_Click()

If (Range(“E35”).Value) <> Range(“E6”).Value   Then
    Range(“F35:AQ35”).Cut Range(“E35:AP35”)
   
    Application.CutCopyMode = False

End If
End Sub

 

But I don’t want to keep writing this formula for each and every cell. Is there any way to loop this code?

By: Nabeela

Leave a Reply

Your email address will not be published. Required fields are marked *