Loop Until out of named range

  • Thread starter Thread starter kylekelsch
  • Start date Start date
K

kylekelsch

I have a Loop that I want to go until it is out of my named range
something like so


Lets say I have a named range called "HiField"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Dim ntotal as string

ntotal = 0

Do
Range("CP1").Offset(ntotal, 0) = "HI"
ntotal = ntotal + 1
Loop Until out of HiField <------This is were I need Help

How would I go about telling it to loop until out of named range
 
You can use intersect
set ColCPRange = Range("CP:CP")

set Newrange = Application.Intersect(ColCPRange, HiField)
for each cell in NewRange

next cell
 
Loop Until Intersect(Range("CP1").Offest(ntotal,0),Range("HiField")) Is Nothing
 
This should work:

ntotal = 0
For Each cell in ActiveSheet.Range("HiField")
Range("CP1").Offset(ntotal, 0) = "Hi"
ntotal = ntotal + 1
Next
 
P.S. Don't Dim ntotal as string if you are going to use it as an integer. It
will cause a type mismatch error.
 
Not sure is I'm getting the full meaning of your q, but

Sub tester()
For Each c In Range("Test")
MsgBox "Your Value is " & c.Value
Next c
End Sub

This worked for me (Test is a named range
C4:C7 - with values 123,456,789,001
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top