+ Reply to Thread
Results 1 to 9 of 9

VBA Code: how to use merged cell as range for a If and Formula statement

  1. #1
    Registered User
    Join Date
    10-14-2014
    Location
    Porto
    MS-Off Ver
    2010
    Posts
    9

    VBA Code: how to use merged cell as range for a If and Formula statement

    Hi guys,

    First of all I'm sorry the title isn't too descritive (as asked) but I can't quite figure out how to put it!!

    so,

    I have an excel sheet that allows me to control a series of ongoing operations. These operations consist in a series of events performed by diferent teams. In my sheet I have a control for the events (Collumn D in excel attached) that turns "finished whan all Team 'X' events are finished and shows "Ongoing" when the Team hasn't finished all events. (Please note that in the attached excel the control not working because the tickboxes are not correctly linked to the cells but is working just fine in my excel sheet!)

    The problem is that I wanted to introduce a new macro that inserts the following formula in column A:

    IF(AND(D3="Finished";D4="Finished";D5="Finished";D6="Finished");"Operation Closed";"Operation Ongoing")

    And I can't quite figure it out as the range for the IF statement might be variant allthought it's always the same as the range of the merged cells in column A!!

    The attached file might give you a better idea of what I mean:
    Book3.xlsx

    Can anyone please help on this code??

    Many thanks

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    10-14-2014
    Location
    Porto
    MS-Off Ver
    2010
    Posts
    9

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Thank you PCI. It was a great first help, but it still doesn't consider the merged cells range as variant.
    Consider the attached file:
    Book3.xlsm

    For operation B, the operation is being deemed as "Operation Closed" even though Team E hasn't finnish all events. Similarly, operation C is being deemed as "Operation Ongoing" even though teams A to C have all finished their events.

    Thus, the code you provided does almost exactly what I wanted, but the trick is to know if we can program the IF AND statement range equal to the range of the merged cells! Anyone can help?

    Many Thanks

  4. #4
    Forum Contributor
    Join Date
    06-04-2013
    Location
    Moscow
    MS-Off Ver
    Office 365
    Posts
    100

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Please Login or Register  to view this content.
    See in yellow cells
    Attached Files Attached Files
    I'm sorry my english...

  5. #5
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Quote Originally Posted by Acosta View Post
    Thank you PCI. It was a great first help, but it still doesn't consider the merged cells range as variant.
    Consider the attached file:
    Attachment 356376

    For operation B, the operation is being deemed as "Operation Closed" even though Team E hasn't finnish all events. Similarly, operation C is being deemed as "Operation Ongoing" even though teams A to C have all finished their events.

    Thus, the code you provided does almost exactly what I wanted, but the trick is to know if we can program the IF AND statement range equal to the range of the merged cells! Anyone can help?

    Many Thanks
    For Operation B... D11 is not in the Formula so Team E is not counted. A - D are Finished so Operation Closed.

    For Operation C... Team E from Operation B (Cell D11) is included in the Formula. Team E not Finished so Operation Ongoing.

    Works Fine or?

    Regards

    JRidge

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Try
    If it's not correct, explain the formula you want to put in.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-14-2014
    Location
    Porto
    MS-Off Ver
    2010
    Posts
    9

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    PCI,

    I think that's exactly it, but I haven't tested it through!! Very Ingenious... Thanks!

    I just had to add a -1 at the end of NbRow= ...

    Let me have a definitive comment on your suggestion tomorrow!

    Thanks again

  8. #8
    Registered User
    Join Date
    10-14-2014
    Location
    Porto
    MS-Off Ver
    2010
    Posts
    9

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    PCI,

    2 quick adaptations and the code is doing exactly what I wanted:

    1) While (I < LastRow) becomes While (I <= LastRow)

    2) The - 1 goes in ... SUMPRODUCT(--(RC[3]:R[" & NbRow -1& "]... and the range is just perfect!

    Many thanks for the help... great job

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA Code: how to use merged cell as range for a If and Formula statement

    Acosta,
    Great thanks, you made the modifications to show you can handle the code, this is perfect, I'm very please.

    Patrick

+ 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. Offsetting from a Cell within a Merged Range
    By exceere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-04-2014, 12:45 AM
  2. If statement formula for range not changing requested cell to yes
    By Exceldope in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-20-2012, 12:14 PM
  3. [SOLVED] Value in a merged cell with a range name
    By dohzer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2012, 07:20 AM
  4. For Each cell in range and If statement. Prevent code moving on until If met
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2012, 11:28 AM
  5. [SOLVED] If Statement: How to test if a cell is merged or not?
    By Dr. M in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2005, 11:05 AM

Tags for this Thread

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