Consulting

Results 1 to 5 of 5

Thread: IF and Offset Macro

  1. #1

    IF and Offset Macro

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    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

  3. #3
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    thank you so much, it work perfectly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •