How to return a range object that is just the first colmn of a named range covering multiple columns?
Hi,
I have a named range which unfortunately covers three columns because the cells are merged (and unmerging is not an option in this case). What I'm trying to achieve is if a cell in the FoodCategory range is blanked out, that the corresponding food item in column D is balnked out also. With the code below, if I hard code the range it works fine. If I use the named range (commented out in the sample below) it fails because the named range actually refers to the range A24:C28 due to the cells being merged for the FoodCategory range.
How can I return a range object that represents just the first column of the FoodCategory range. i.e. replicate what I've hard coded below without hard coding the range.
'****************************
'Check for changes in "FoodCategory" range in order to clear out the corresponding FoodValue when food category is blanked out
If Not Intersect(ActiveCell, Range("FoodCategory")) Is Nothing Then
Dim rng1 As Range
Dim rng2 As Range
'Set rng1 = ActiveSheet.Range("FoodCategory") 'refers to A24:C24
Set rng1 = ActiveSheet.Range("A24:A28")
For Each rng2 In rng1
'even though food item is in column D, the Offset to blank it out is only 1 as A-C are merged.
If rng2 = "" And rng2.Offset(, 1).Value <> "" Then rng2.Offset(, 1).Value = ""
Next
End If
'*****************************
Recent comments
5 years 42 weeks ago
6 years 28 weeks ago
6 years 40 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 49 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago