+ Reply to Thread
Results 1 to 16 of 16

Macro: If cell blank, copy from column next to it

  1. #1
    Registered User
    Join Date
    10-22-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    30

    Macro: If cell blank, copy from column next to it

    Hi,

    I have column A and B.

    There are some blank cells in column A. I need a macro that would find these blank cells, and if blank, copy the data that is on the cell right next to it in column B.

    Example: A1 is blank, copy from B1; A2 is blank, copy from B2.

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: Macro: If cell blank, copy from column next to it

    Maybe this will do the trick.
    Please Login or Register  to view this content.
    Harry.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro: If cell blank, copy from column next to it

    You mean like this

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-22-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Macro: If cell blank, copy from column next to it

    Sub hsv()
    With Columns(1).SpecialCells(4)
    .Value = .Offset(, 1).Value
    End With
    End Sub

    Ok this one worked.

    So now, what if Column A STILL has blank cells...grab data from next column so, Column C

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro: If cell blank, copy from column next to it

    I have tested mine as well. It works as long as column B is not blank

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Macro: If cell blank, copy from column next to it

    Maybe something like this?

    Please Login or Register  to view this content.
    @Harry (hsv)
    Harry.
    When I use your code, it uses the offset value for the first empty cell at the all the empty cells. (??????)
    Groetjes

    John

  7. #7
    Registered User
    Join Date
    10-22-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Macro: If cell blank, copy from column next to it

    Thanks everyone! For some reason, AB33's macro doesnt work.. :/ not sure why.

    So one more.. Let's say that instead of the next column, its a completely different column.

    So initial data is in column Z, and if blank...I would like to copy data from column C. I tried:

    Sub hsv()
    With Columns(25).SpecialCells(4)
    .Value = .Offset(, -22).Value
    End With
    End Sub

    It doesn't work.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Macro: If cell blank, copy from column next to it

    Is Column Z not Column 26?
    Offset accordingly

  9. #9
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: Macro: If cell blank, copy from column next to it

    Quote Originally Posted by jolivanes View Post
    @Harry (hsv)
    Harry.
    When I use your code, it uses the offset value for the first empty cell at the all the empty cells. (??????)
    Groetjes

    John
    You're right John.
    I've tested it with blank cells on the bottum of the column.
    Not in the middle of the column with blank's.

    Hope this is better.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Macro: If cell blank, copy from column next to it

    Hoi Harry.
    You're up late in the evening!
    Not to worry Harry, it was just an observation.
    As you more then likely saw, I went a similar way.

    Welterusten

    John

  11. #11
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: Macro: If cell blank, copy from column next to it

    Hoi John,

    I saw it.
    Except your last cell in kolom A is not included if column B is slightly longer.
    That is a small difference.

    Uiteraard ook welterusten.

  12. #12
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Macro: If cell blank, copy from column next to it

    @noidea_4

    To use HSV's code, it would look something like this:

    Please Login or Register  to view this content.
    @ Harry
    Never even thought about that Harry.
    Thank you for setting me straight.

    Regards
    John

  13. #13
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    860

    Re: Macro: If cell blank, copy from column next to it

    You're welcome John.

  14. #14
    Registered User
    Join Date
    10-22-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Macro: If cell blank, copy from column next to it

    Thanks again!!!
    Jolivanes, i'm curious as to what .SpecialCells(4) means?

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro: If cell blank, copy from column next to it

    It means xlCellTypeBlanks Empty cells

  16. #16
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Macro: If cell blank, copy from column next to it

    Here is one

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1