Results 1 to 8 of 8

Thread: VBA Scan column is case of blank cell copy the cell to the right in the blank cell

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    17

    VBA Scan column is case of blank cell copy the cell to the right in the blank cell

    Hello All,

    I'm looking for a piece of code that wil scan a column and when it comes on a blank cell or empty cell it wil copy the cel on the right and past it in the blank cell and then continiues.

    Hope you could help?

    Kind regards,

    Arne

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    My column to be "scanned" is A, starting in row 1. My column from which to grab the values to populate the blank cells is B.

    Code:
    Sub fillBlanks()
        Dim i As Integer
        Dim lastRow As Integer
        Dim ws As Worksheet
        
        Set ws = ActiveSheet
        lastRow = ws.Range("a" & Rows.Count).End(xlUp).Row
        
        For i = 1 To lastRow
            If ws.Range("a" & i).Value = "" Then
                ws.Range("a" & i).Value = ws.Range("b" & i).Value
            End If
        Next i
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    17

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    Sound and Safe!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    17

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    Hello Bryce,

    I've tried this on column E and F but it didnt work as there is text in these rows.
    When i've added numbers in E and F it did work.

    Hmmm Could you help?


    Sub fillBlanks()
    Dim i As Integer
    Dim lastRow As Integer
    Dim ws As Worksheet

    Set ws = ActiveSheet
    lastRow = ws.Range("e" & Rows.Count).End(xlUp).Row

    For i = 1 To lastRow
    If ws.Range("e" & i).Value = "" Then
    ws.Range("e" & i).Value = ws.Range("f" & i).Value
    End If
    Next i
    End Sub

  5. #5
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    shouldn't matter if it's numbers or text. see attached and let me know if yours is different.
    Attached Files Attached Files

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    17

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    There is something with the cells in row E and F tried to delete all formulas and make the cells nutral. Save the file in a different formate

    Your code works like clockwork in any other cells......

    unfortunatly I can't post the file here....

  7. #7
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    I don't understand what's not working exactly. The file I attached in post #5 has strings in columns E and F and looks to work how you want it to. Did you run the macro in it and find it not to fill in the blanks as you'd expected?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    17

    Re: VBA Scan column is case of blank cell copy the cell to the right in the blank cel

    The file when it opens is in .csv format when I save it in .xls it works but only in a few cells then it stops...

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width