+ Reply to Thread
Results 1 to 3 of 3

VBA - Move text in one cell if another cell is not blank

  1. #1
    Scott Wagner
    Guest

    VBA - Move text in one cell if another cell is not blank

    In a worksheet I have some cells that aren't arranged consistently that
    contain product information. In most cases the cells are arranged fine, but
    there are certain lines that I am having trouble with and I want to
    reposition cell contents around.

    In the cases I want to effect column A contains a number, in all other cases
    that cell is empty. Hoping column A can be used as a "trigger" for the VBA.

    Row 1 contains headers, so all this begins on row 2.

    Here is the basic logic:

    IF A2 is not empty THEN
    Move contents of C2 to D2
    Move contents of B3 to C2


    Example (before):
    A | B | C | D |
    1 | 1 | Text1 | |
    | Text2 | | |
    2 | 1 | Text3 | |
    | Text4 | | |
    3 | 1 | Text5 | |
    | Text6 | | |

    Example (after):
    A | B | C | D |
    1 | 1 | Text1 | Text2|
    | | | |
    2 | 1 | Text3 | Text4 |
    | | | |
    3 | 1 | Text5 | Text6 |
    | | | |

    Thanks in advance!

    Scott

  2. #2
    Crowbar via OfficeKB.com
    Guest

    Re: VBA - Move text in one cell if another cell is not blank

    I have tested this and it worked fine. Don't know how clued up on this you
    are so here are a few things:

    If you place this within you worksheet it will activate evertime you open it,
    if you don't want this then change the sub name to something else.

    This current sub will only work on a sheet named Sheet1, if your sheet is
    called something else then rename sheet1 (on the thrid line) to
    Sheets("YOUR SHEET NAME")

    Please note that this ONLY does as you stated, which is: -

    If Ax is empty then
    Cx is put into Dx and
    Bx + 1 is put into Cx


    Sub auto_open()

    For x = 1 To 65536
    If Sheet1.Cells(x, 1).Value > "" Then
    Range("C" & x).Cut
    Range("D" & x).Select
    ActiveSheet.Paste

    Range("B" & x + 1).Cut
    Range("C" & x).Select
    ActiveSheet.Paste
    End If
    Next x

    End Sub


    Regards Crowbar

    Email: [email protected]

    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...mming/200603/1

  3. #3
    Scott Wagner
    Guest

    Re: VBA - Move text in one cell if another cell is not blank

    Thanks~!

+ 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