PDA

View Full Version : [SOLVED] IF and Offset Macro



yoitsmejy
06-21-2011, 06:18 AM
Hi guys,

I am trying to move whatever is in column C to column B if it does not contain "123123". I am having problem on writing the macro. I think the best way is using offset, but i am not experience with using offset and therefore it have some error. Please help me with the code or if you have any suggestion that will make it more faster and efficient. Thanks.


With ws.Cells(Lrow, "C")
If Not IsError(.Value) Then
If .Value = "123123" Then .ClearContents
If Not .Value = "123123" Then ActiveCell.Offset(0, -1).Select
End If
End With

Paul_Hossler
06-21-2011, 06:25 AM
Just using a cell, does not make it the ActiveCell

Maybe something like ... (not tested)




With ws.Cells(Lrow, 3)

If Not IsError(.Value) Then

If .Value = "123123" Then
.ClearContents
Else
.Offset (0, -1).Value = .Value
End If

End With


Paul

yoitsmejy
06-21-2011, 06:53 AM
Paul,
when i run your code, it cleared out the 123123 which is perfect, but it didnt move the rest of it with values to column B.

Bob Phillips
06-21-2011, 09:50 AM
With ws.Cells(Lrow, 3)
If Not IsError(.Value) Then
If .Value = "123123" Then
.ClearContents
Else
.Offset(0, -1).Delete Shift:=xlToLeft
End If
End If
End With

yoitsmejy
06-21-2011, 12:36 PM
thank you so much, it work perfectly :)