Looping through 2 ranges

craigg3

Board Regular
Joined
Dec 23, 2002
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
I have 2 ranges I need to loop through. Both are defined name ranges.

aRange is cell a1:a20
cRange is cell c1:c20
both ranges may increase or decrease but will stay the same rows for both

I need to check to see if there is a value in the cRange that is greater or less than 0 and if aRange = "" then
select the aRange cell and exit the sub. If condition is false continue

I have tried multiple ways and none seem to work so figured I would just post what im trying to do. Thanks.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
VBA Code:
Sub Macro1()

For Each c In Names("cRange").RefersToRange

If Range(c.Address).Value <> 0 And IsNumeric(Range(c.Address).Value) = True And Range(c.Address).Offset(0, -2).Value = "" Then
Range(c.Address).Select
'Range(c.Address, Range(c.Address).Offset(0, -2)).Select
Exit Sub
End If
Next c

End Sub
 
Last edited:
Upvote 0
VBA Code:
Sub Macro1()

For Each c In Names("cRange").RefersToRange

If Range(c.Address).Value <> 0 And IsNumeric(Range(c.Address).Value) = True And Range(c.Address).Offset(0, -2).Value = "" Then
Range(c.Address).Select
'Range(c.Address, Range(c.Address).Offset(0, -2)).Select
Exit Sub
End If
Next c

End Sub
Great, thanks for the help. Seems to be working as needed.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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