Using Debug.Print with Range Variable with more than one cell

E

ExcelMonkey

I have a range variable. I want to print its value to the Immediate Window
upon selection of it.

Currently I use this to do so:
var1 = Target
Debug.Print var1

However this fails if the range is greater than one cell. How can I modify
this to print all values in the selection?

Thanks

EM
 
J

Jeff

This way your range can be dynamic

Sub way()
Dim yourVariable As Range
Dim i As Long
Set yourVariable = Selection
For i = 1 To Selection.Cells.Count
Debug.Print yourVariable(i)
Next
End Sub
 

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

Top