Looping through filtered rows with multiple columns

HANSEMINATOR

New Member
Joined
Nov 10, 2013
Messages
6
Using the advancedfilter I find rows in my data which have certain criteria.

I'd like to make a calculation where i subtract to cells in each of and sum the result.

Using the code below creates a loop which runs through all visible cells in all rows. I only need to run through each visible row once.

It is probably some easy thing, I can't see...

Code:
For Each rng In filrng.Rows.SpecialCells(xlCellTypeVisible)
 //Code substracting one cell from another while adding it to a sum
Next rng

Regards
Hans
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe a before-and-after example would help.
 
Upvote 0
Sorry about that.

filrng is a Range which basically covers an entire datasheet filled with information on people who have started and ended different courses. So a multicolumn range with columns describing hometown, start date, end date, status etc..

Based on some criteria I filter these people using advancedfilter.

Code:
    Dim filrng As Range
    Set filrng = Sheets("Datasheet").Range(Sheets("Datasheet").Cells(1, 1), Sheets("Datasheet").Cells(numberofentries, 25))

    filrng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
    Sheets("criteriasheet").Range("A1:D2"), Unique:=False

The rows which pass through the filter all have a start date cell and an end date cell. I'd like to subtract start date from end date and sum the difference of all rows which has passed the filter criteria. How to do this is my question.

I have, among other things, tried using.

Code:
  Dim rng As Range
  For Each rng In filrng.Rows.SpecialCells(xlCellTypeVisible)
        
    
  Next rng

But this iterates through each cell in each of the filtered rows. I'd like to just iterate row by row through my filrng.

Hope my question and the context is clearer now :)
Thanks
 
Upvote 0
Maybe

Code:
For Each rRow In filrng.SpecialCells(xlCellTypeVisible).Rows
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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