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

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
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
 
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
 
Back
Top