+ Reply to Thread
Results 1 to 4 of 4

Copy Cell data if adjacent cell is empty

Hybrid View

  1. #1
    Registered User
    Join Date
    03-04-2014
    Location
    manila, philippines
    MS-Off Ver
    Excel 2010
    Posts
    22

    Copy Cell data if adjacent cell is empty

    Can I ask for a sample code for my problem. I want to copy data in the cell if the following cell is empty.

    Sample

    Column A Column B Column C
    Orange
    Red ABC:Red


    Now when I run the code that im asking this what the output should look like

    Column A Column B Column C
    Red ABC:Red Orange

    Since Orange is in Cell A and Cell B is empty then Cell A data is moved to Cell C and then those under them will be pushed upward as if the user has deleted a cell to move the data upwards,

    Hope you get my point.
    Last edited by rflorentino; 05-09-2014 at 07:09 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy Cell data if adjacent cell is empty

    Hi r,

    Try this:

    Sub rflor(): Dim A As Range
    For Each A In Range("A:A")
    If A <> "" Then
    If A.Offset(0, 1) = "" Then _
        A.Cut A.Offset(0, 2)
    End If: Next: End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-04-2014
    Location
    manila, philippines
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Copy Cell data if adjacent cell is empty

    Quote Originally Posted by xladept View Post
    Hi r,

    Try this:

    Sub rflor(): Dim A As Range
    For Each A In Range("A:A")
    If A <> "" Then
    If A.Offset(0, 1) = "" Then _
        A.Cut A.Offset(0, 2)
    End If: Next: End Sub


    Hi Sir

    Is it possible to cut the data only. In your code it seems like it is cutting the border as well.

    Thanks/

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy Cell data if adjacent cell is empty

    Hi r,

    You can do this instead:

    Sub rflor(): Dim A As Range
    For Each A In Range("A:A")
    If A <> "" Then
    If A.Offset(0, 1) = "" Then
    A.Offset(0, 2) = A: A = ""
    End If: End If: Next: End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to copy data from one cell to another if adjacent cell meets certain requirements?
    By rrokicki in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-08-2016, 07:41 AM
  2. Do not return a value when adjacent cell in two columns of data is empty
    By randinator in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-03-2014, 01:53 PM
  3. [SOLVED] Macro to find the empty cell in a column and copy a adjacent row to another column.
    By naga in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2013, 07:44 AM
  4. Replies: 1
    Last Post: 03-02-2010, 01:23 PM
  5. Replies: 1
    Last Post: 02-06-2008, 08:23 AM

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