Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88050

Combine NEXT function with a variable (named range) from the name manager

$
0
0

I have the following VBA to insert a value into each sheet using the NEXT function:

Sub Insert_Values()
Dim b As Worksheet
For Each b In Worksheets
    Dim Range As Range
    Set Range = b.Range("B2:C4")
    b.Select
    Range.Value = 1
Next b
End Sub

All this works fine so far.


However, now I want to use a named range instead of Set Range = b.Range("B2:C4").
Therefore, I assigned Range_01 in the name manager to the Range("B2:C4") looking like this:


enter image description here


In the VBA I changed:

Dim Range As Range
Set Range = b.Range("Range_01")

Now, I get runtime error 1004.

I assume the reason is that in the name manager the Sheet1 is fixed assigned to the Range_01.
Therefore, I am wondering if there is way to assign a named range but without a fixed Sheet so the NEXT function can still run through all sheets?


Viewing all articles
Browse latest Browse all 88050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>