+ Reply to Thread
Results 1 to 16 of 16

Using muitiple ranges within a loop to process if function..

  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Using muitiple ranges within a loop to process if function..

    Hi All,

    My first post on here so hopefully will be useful.

    I am writing a validation program in VBA and I can't figure out how to use muitiple ranges and if statements within'. Here's my requirements:

    - If a cell in column1 = 1 and on the same row column2 > 5 then colour that cell in column2 red

    I have used "for each cell in range ..." in a linear way to apply speicific column validation but I can't work out how to cross column check.

    Any help would be hugely appreciated.

    Many thanks,
    Jordan

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    No need to loop through the cells:

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Hi Walruseggman

    Thanks for your promp reply. Could you break that down for me.. I am using named ranges .. I understand the code is filtering on the requirements but not sure how to pop in my named column ranges?

    Cheers,
    Jordan

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    Assuming from your original post:

    column1 (the =1 column) is named "name1", and
    column2 (the >5 column) is named "name2", then:

    Please Login or Register  to view this content.
    If this isn't what you want, please post an example workbook with sample data and expected output.

  5. #5
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Ran your script with my ranges in and getting Error "Medthod 'range' of object'_global' failed"

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    please post an example workbook with sample data and expected output.
    *******************

  7. #7
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Hi Walruseggman,

    Sorry; Here's a link to the workbook:

    http://www.excelforum.com/attachment...1&d=1464096566

    As you can see "name1 = BLDGCLASS"
    "name2 = NUMSTORIES

    In this work book the rules will be applied to columns J and M.

    Many thanks,
    Jordan

  8. #8
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    Link is broken. Can you use the picture icon (with the tree) to try to upload, please?

  9. #9
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    sample data 0516.xlsx

    That better?

  10. #10
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    So i realize it was an innocent mistake, but be careful with the term "named ranges". Named ranges are an actual thing in Excel, where you can assign a group of cells a name and then refer to that name instead of the group of cells (Ctrl + F3 gets you there). And that's how the code i provided works.

    So two questions:
    1. With the sheet you uploaded, it looks like you just meant you have column headers that have the names you mentioned. Just to be sure, can you clarify which approach you meant? Named ranges, or column headers?
    2. Your original post says you want =1, >5 highlighted, but you have a 2, 37 highlighted and nothing else. I would have expected Columns M cells in rows 2, 3, and 7 highlighted. Whats going on here?

  11. #11
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Hi Walruseggman

    1 - Yes I meant column headers; in SAS code which I am more fmailiar with we use named variables/ranges so this is my mistake
    2- Slight change of logic to =2 for 1st criteria

    Thanks for your help again

  12. #12
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Hi Walruseggman

    1 - Yes I meant column headers; in SAS code which I am more fmailiar with we use named variables/ranges so this is my mistake
    2- Slight change of logic to =2 for 1st criteria

    Thanks for your help again

  13. #13
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    That has done it; though I added the following snippet after the auto filter clear so that the first row was not highlighted:

    Please Login or Register  to view this content.
    Many thanks for your help with this

  15. #15
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Using muitiple ranges within a loop to process if function..

    You probably don't want to do it that way, as Active Cell could be anything, and you don't need specialcells here anyway. I would do:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-07-2013
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Using muitiple ranges within a loop to process if function..

    Perfect thank you

+ 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. [SOLVED] sumproduct muitiple criteria with greater than function
    By shellwig in forum Excel General
    Replies: 6
    Last Post: 01-05-2016, 03:13 PM
  2. Repeat or Loop Process for each value in a list for saving new filesin VBA
    By adambriggs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2015, 03:44 PM
  3. [SOLVED] how can I take the value of several selected cells and process them in a loop ?
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2014, 03:00 AM
  4. Spawn a child process? to run the loop, then move on
    By GoonerJed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2013, 08:41 AM
  5. [SOLVED] LookUP formula matching muitiple conditions
    By Excel Dumbo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-08-2013, 08:56 PM
  6. VBA to create specific named ranges and repeating process (Loop?) across columns
    By vinothj86 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-30-2012, 05:01 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