Consulting

Results 1 to 3 of 3

Thread: If then Else to fill blank cells

  1. #1
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location

    Question If blank, then copy paste from cell, else leave alone

    Hello All,

    i am looking for a macro that will look in column B for any blanks, if there is a blank cell in B, then i want it to copy and paste the data from the cell in column A into column B.

    So for example. I have 10 rows x 2 columns of data.
    (there will be much more than 10 rows on the real worksheet, This macro should loop to last row)

    The Macro looks in collumn B and finds that B6 and B4 is Null. It will then copy and paste A6 to B6 and A4 to B4, and continue to last row.
    A B
    1 2 1
    2 2 1
    3 2 1
    4 3 3
    5 2 1
    6 2 2
    7 2 1
    8 2 1
    9 2 1
    10 2 1

    Thank you for your time,
    Zlerp
    Last edited by Zlerp; 11-20-2014 at 10:05 AM.

  2. #2
    Sub Zlerp()
    
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    
    For x = 1 To LastRow
    If Range("B" & x).Value = "" Then Range("B" & x).Value = Range("A" & x).Value
    Next x
    
    
    End Sub

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    also

    Sub FillBlanks()
        Dim r As Range
        On Error Resume Next
        For Each r In ActiveSheet.Cells(1, 1).CurrentRegion.Columns(2).SpecialCells(xlCellTypeBlanks)
            r.Value = r.Offset(0, -1).Value
        Next
        On Error GoTo 0
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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