+ Reply to Thread
Results 1 to 6 of 6

Two If's and ranges to loop?

  1. #1
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    64

    Question Two If's and ranges to loop?

    I have a sheet where I want to select multiple items (ctrl click, not drop down) from column E, and then look at each cell in the neighboring 65 columns for conditional formatting and hide any that do not have active formatting. I have it working if it looks through every cell in the 65 column range, but the real document has 700 rows and locks up when it runs. My thought was to either only look in the rows that offset the selected cells, only look at the visible rows, or fill the selections with color and use those to identify the offset rows/cells I want it to look through.

    Whether I use selected cells, formatted cells or hidden rows to identify the corresponding second range to filter columns for, I can�t figure out how to require two if�s and two loops at the same time. In the example attached, running the �Run Both� macro when all selections are made from column E will fill those selected cells with color and then hide the rows that are not shaded. The problem comes when it gets to the second half of the macro, which is hiding any of the 65 columns to the right of the shaded cells that do not have conditional formatting.
    Can anyone help me figure out how to tell it to only look at the selected rows (which will differ each time it�s used) and then only look at the corresponding 65 rows when it identifies and hides columns?

    **Update*** There were a couple of things I should have mentioned in my original post.

    To keep the sub columns together with dates at all times, the area being filtered (Sheet1 of attachment) is not an actual table. and

    Some of the cells that I need to keep will be blank with only conditional formatting activated. .

    ** Updated Attachment
    Attached Files Attached Files
    Last edited by Anita Knapp; 10-13-2024 at 05:41 PM. Reason: Added Attachment

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,141

    Re: Two If's and ranges to loop?

    No sample file attached.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    64

    Re: Two If's and ranges to loop?

    Duh, sorry! I must have hit upload before I closed the window. It's now attached.

    Thank you!

    Quote Originally Posted by JohnTopley View Post
    No sample file attached.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,879

    Re: Two If's and ranges to loop?

    See the attached workbook. Used Power Query to filter with a parameter query. Once filtered, close and load to Data Model, where build a Pivot Table with only the value information.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    09-25-2022
    Location
    West Coast, USA
    MS-Off Ver
    365 - Version 2308
    Posts
    64

    Re: Two If's and ranges to loop?

    If I’m understanding correctly, instead of VBA to hide columns and rows, there would be a separate drop down and the results would populate on a separate table?

    I'm hoping to do it with vba/hiding the existing data on Sheet1 because there are 12 of these, and there are already 11 large queries that run to build the background data. I have a version with an identical Sheet where instead of hiding rows it sends only the selected ID’s to a separate sheet and then the user hides columns and does the work needed from there but if I can figure out how to have it do rows and columns, it would be much simpler for the user.

    There were a couple of things I should have mentioned in my original post. To keep the sub columns together with dates at all times, the area being filtered (Sheet1 of attachment) is not an actual table. The other thing is that some of the cells that I need to keep will be blank with only conditional formatting activated.
    I’ve updated the original attachment.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,879

    Re: Two If's and ranges to loop?

    If I’m understanding correctly, instead of VBA to hide columns and rows, there would be a separate drop down and the results would populate on a separate table?
    This is a true statement. You will need to be patient and await one of the VBA experts for help with your specific request. What you are asking is not in my wheelhouse.
    Last edited by alansidman; 10-13-2024 at 06:57 PM.

+ 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. For each loop only displaying last loop in all of my ranges
    By mickeyb121 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2017, 06:52 AM
  2. Replies: 5
    Last Post: 12-07-2016, 07:41 AM
  3. Loop through three ranges
    By jkj115 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2015, 02:46 PM
  4. Using a For Loop with Ranges
    By an0593 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2013, 02:28 AM
  5. Do While Loop Q: Copying sheet data ranges to another sheet's ranges
    By foolios in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-30-2011, 05:05 PM
  6. Loop thru two ranges
    By mindoff in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-22-2010, 07:46 AM
  7. using for-loop to name ranges
    By mashoutposse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2010, 08:09 AM

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