Set Range for Loop of Rows

vck2017

New Member
Joined
Jan 13, 2017
Messages
8
I am trying to set a range for a set of columns (rg2) and rows by using Intersect. The rows are only to be selected for the range where there is a conditional "x" mark in a column. I can not set this loop as a range somehow or include this in the intersect range setting.
I appreciate anyone's advise.

Code:
    For Each c In Range(Cells(StartR, 2), Cells(StartR + Size - 1, 2))
    If c = "x" Then Rows(c.Row).Hidden = False
    Next c


    '  Set rg = Range(c.Row)

    Set rg3 = Intersect(c.Row, rg2)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Maybe something like
Code:
   Dim Cl As Range, Rng As Range
   For Each Cl In Range("A1:A20")
      If Cl.Value = "x" Then
         Cl.EntireRow.Hidden = False
         If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
      End If
   Next Cl
   Set Rng = Intersect(Rng.EntireRow, Range("H:H"))
 
Upvote 0
Maybe something like this if I understood you correctly:
Code:
    set rg2 = nothing
    For Each c In Range(Cells(StartR, 2), Cells(StartR + Size - 1, 2))
    If c = "x" Then 
         Rows(c.Row).Hidden = False
         if not rg2 is nothing then
             set rg2 = Union(rg2, c.EntireRow)
        else
            set rg2 = c.Entirerow
       end if
    end if
    Next c
not tested.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top