+ Reply to Thread
Results 1 to 3 of 3

vba If statement - If cell not blank copy a cell value from other sheet

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    Gisburn
    MS-Off Ver
    Excel 2010
    Posts
    10

    vba If statement - If cell not blank copy a cell value from other sheet

    Hello everyone,

    I'm struggling with trying to create a series of vba "if" statements.

    On sheet 3, I have columns (A:T) that will hold values, there will be a maximum of 8 rows that will contain text. However, its not a given that all 8 rows will contain text (it may be 5,6 or 7.) There are 3 colums (F,G,H) whose values I want to retrieve from sheet 2 (that are calculated by forumla). I only want that value if Column A of that particular row has a value within it.


    So let me try and explain what I mean if I can by using an if statement (but not with the correct syntax.)

    In Sheet 3 IF A2 IS NOT BLANK then Copy value from Sheet 2 Cell B24 and paste into Sheet 3 Cell F2
    In Sheet 3 IF A3 IS NOT BLANK then Copy value from Sheet 2 Cell B24 and paste into Sheet 3 Cell F3

    In Sheet 3 IF A2 IS NOT BLANK then Copy value from Sheet 2 Cell H20 and paste into Sheet 3 Cell G2

    etc etc

    I hope you can see where i'm going with this.

    I'd do this by a normal cell formula if possible, however within the macro that i'll assign this code to, i'll be clearing the contents of sheet 3 once i've copied this over to a different workbook, and doing this seems to clear the formula within the cell. (Plus I personally find VBA much slicker.)

    If anyone can help me i'd appreciate it alot.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba If statement - If cell not blank copy a cell value from other sheet

    Hello Dream Ahead,

    I follow this part of the post...
    In Sheet 3 IF A2 IS NOT BLANK then Copy value from Sheet 2 Cell B24 and paste into Sheet 3 Cell F2
    In Sheet 3 IF A3 IS NOT BLANK then Copy value from Sheet 2 Cell B24 and paste into Sheet 3 Cell F3

    However, this line has me puzzled. Is there a typographical error because A2 has already been used?
    In Sheet 3 IF A2 IS NOT BLANK then Copy value from Sheet 2 Cell H20 and paste into Sheet 3 Cell G2
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-18-2012
    Location
    Gisburn
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: vba If statement - If cell not blank copy a cell value from other sheet

    Quote Originally Posted by Leith Ross View Post
    Hello Dream Ahead,

    I follow this part of the post...


    However, this line has me puzzled. Is there a typographical error because A2 has already been used?
    Hi Leith,

    Thanks for the reply. I've been rather busy so not had chance to respond. I'll try and explain it as best as possible because I've made it a bit confusing.

    If A2 is not blank then:
    i want to copy the value of sheet 2 cell b24 to sheet 3 cell f2.
    And I want to copy the value of sheet 2 cell h20 to cell g2.
    And I want to copy the value of sheet 2 cell i20 to cell h2.

    If a3 is not blank then:
    I want to copy the value of sheet 2 cell b24 to sheet 3 cell f3.
    And I want to copy the value of sheet 2 cell h21 to cell g3.
    And I want to copy the value of sheet 2 cell i21 to cell h3.

    Etc etc throughout the whole rows on the sheet checking column a.

    If the cell in column a is blank, then do nothing.

    Hope that clears it up a bit.

+ 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