+ Reply to Thread
Results 1 to 6 of 6

Macro to check if range of cells values are balnk...then do something

  1. #1
    Registered User
    Join Date
    12-31-2008
    Location
    Chester, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Macro to check if range of cells values are balnk...then do something

    Hi - I am looking for a macro that will check 2 things....then do something.
    The first is if a range of cell values in are blank. lets say
    Sheets("Sheet1").Range("D6:G48").
    Next is if a particular cell contains a given value ,
    Sheets("sheet1").Range("E5") should equal "Year 1" if true.
    If both these are true then I want the macro to copy a range of cells from
    Sheets("Sheet2").Range("H6:H48") to Sheets("Sheet1").Range("D6:D48").

    I tried to use IsEmpty but it seems to return a "False" if a range of cells
    are being tested.

    Thanks for any help - Jim A
    Last edited by jayers; 01-26-2009 at 11:55 PM.

  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,258
    Hello jayers,

    This macro will copy the range only if both conditions are met. The CountA function will count formula that may not be visible and spaces in cells.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387
    jayers,

    Try:

    Please Login or Register  to view this content.

    Have a great day,
    Stan
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Registered User
    Join Date
    12-31-2008
    Location
    Chester, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Red face macro to look for right column

    OK...that worked great! Especially when I just had only one range of cells labeled by one cell "Year 1".

    How about this though:

    I have five distinct ranges of cells starting with "Year 1" through "Year 5" on Sheet1.
    I have these listed in a combo box on Sheet2 (where I also have a button that activates this macro).
    If "Year 3" is chosen on the combobox, how can I have the macro start checking for the "Year 3" (starting with "Year 1" which all "Years" are in row 5) and when it finds it then checks if the corresponding range is blank...Then performs the copy like you suggested.

    Curious if LOOKUP would work?

    Also - I copied these two sheets to a new workbook that I am attaching (which may have broken links) it is just to help clarify. in Sheet2, range("AR5:AR47") is what I want copied to Sheet1 to the "1st QTR" (which you will see in row 5) of the year chossen in the combo box.

    I hope this is not too confusing and THANKS AGAIN - Jim Ayers
    Attached Files Attached Files
    Last edited by jayers; 01-09-2009 at 12:04 AM.

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    nevada
    MS-Off Ver
    Excel 2012
    Posts
    9

    Re: Macro to check if range of cells values are balnk...then do something

    How do you make this code loop through all columns to the right?

    Quote Originally Posted by Leith Ross View Post
    Hello jayers,

    This macro will copy the range only if both conditions are met. The CountA function will count formula that may not be visible and spaces in cells.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,164

    Re: Macro to check if range of cells values are balnk...then do something

    fredcho,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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