VBA: For Each loop not going through cells in range

FunsizedNerd

New Member
Joined
Mar 20, 2019
Messages
17
This is my code:
'Select range
Set rng1 = Range("K5:N5")
Set rng2 = Range("H6:N56")
Set rng3 = Range("H57:K57")

Set totalrng = Union(rng1, rng2, rng3)
totalrng.Select

'Call SumPassengers sub
For Each cell In totalrng
Call SumPassengers
Next cell

The SumPassengers sub is a large number of if statements and sumifs (that works fine). When I run this code, it puts the sum total in for the first cell in the range (K5) but none of the others in the selected range. How can I fix this?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I think you need to post all of your code but what happens when you step through the code using F8?

Btw, you don't need to select the range.
 
Upvote 0
I do not see any problems with the code you posted (please use code tags), so I am assuming the problem lies in the sub you are calling for each cell.
Like Neil mentioned, use F8 to step through the code to see how the code executes.
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

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