Results 1 to 4 of 4

Thread: VBA Copy and Paste with If statement

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Copy and Paste with If statement

    Hey guys so I am having a issue getting my VBA to recognize my if elseif statement in macro. I want it to read the value of a cell and if the cell is not blank then copy the entire row say A45 to S45 and then copy it, go to a different sheet, insert a new row after the last row of data, and then paste the information into the new row. However if the cell is blank I want it to just do nothing!!

    So far it just seems like my macro ignores part of my if elseif statement and will only do one or the other but it cant tell when the cell is empty or not!

    This is the code I currently have that isnt working.

    Sheets("SOURCE DATA").Select




    If IsEmpty(C45) = False Then


    Sheets("Boise Historical Data").Select


    Sheets("SOURCE DATA").Select


    Range("C45:S45").Copy


    Sheets("Boise Historical Data").Activate


    Range("A1").End(xlDown).Select


    r = Selection.Row
    Cells(r + 1, 1).EntireRow.Insert


    Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

    Else
    End If


    Sheets("Boise Historical Data").Activate


    End Sub



    And this wont do what I want it to. It will work if there is some string of characters in C45 but when I make the cell blank it will still copy the row but with C45 still being empty and its not supposed to!

    Any help would be great!

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,203
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: VBA Copy and Paste with If statement

    Change this
    Code:
    If IsEmpty(C45) = False Then
    to
    Code:
    If Range("C45")<>"" then
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Copy and Paste with If statement

    This worked perfectly! Thanks!!!

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,203
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: VBA Copy and Paste with If statement

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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