Results 1 to 4 of 4

Thread: If then

  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Unanswered: If then

    Hello everyone,

    I have a simple question for you. If a column contains certain information I would like to move it to a different column.

    I know it can be done in VBA but I'm just not sure how. I've tried but failed. I need some direction from the masters.

    For example if column A contains "***" move it to column B.


    Thank you very much
    Carl

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    something like

    Code:
    Sub test()
    Dim Lastrow As Long
    Dim i As Integer
    
        Lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 1 To Lastrow
            If Range("A" & i).Formula = "***" Then
                Range("B" & i).Formula = "***"
                Range("A" & i).Formula = ""
            End If
        Next i
    End Sub
    or do you want to insert a cell
    Code:
    Sub test2()
    Dim Lastrow As Long
    Dim i As Integer
    
        Lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 1 To Lastrow
            If Range("A" & i).Formula = "***" Then
                Range("A" & i).Insert xlShiftToRight
            End If
        Next i
    End Sub
    HTH

    Dave

  3. #3
    Join Date
    Aug 2004
    Posts
    2
    Thank you Dave for your quick reply. I may have miscommunicated my problem . Instead of the column I ment to say the cell.

    For instance

    I want to move the cells that have * before them to another cell in another column. All the other cells in the column can be left alone.

    Thanks again,
    Carl

    I've included a sceen shot of what I'm talking about[IMG]c:/excel.bmp[/IMG]
    Attached Thumbnails Attached Thumbnails excel.bmp  

  4. #4
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    ok sorry about the delay
    Code:
    Sub test2()
    Dim Lastrow As Long
    Dim i As Integer
    
        Lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 1 To Lastrow
            If Left(Trim(Range("A" & i).Formula, 1) = "*" Then
                Range("A" & i).Insert xlShiftToRight
            End If
        Next i
    End Sub
    HTH

    Dave

Posting Permissions

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