ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Debug.Print with Range Variable with more than one cell (https://www.excelbanter.com/excel-programming/426568-using-debug-print-range-variable-more-than-one-cell.html)

ExcelMonkey

Using Debug.Print with Range Variable with more than one cell
 
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

Jacob Skaria

Using Debug.Print with Range Variable with more than one cell
 
var1 = Range("A1:A10")
For Each strval In var1
Debug.Print strval
Next

--
If this post helps click Yes
---------------
Jacob Skaria


"ExcelMonkey" wrote:

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


Jeff

Using Debug.Print with Range Variable with more than one cell
 
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

"Jacob Skaria" wrote:

var1 = Range("A1:A10")
For Each strval In var1
Debug.Print strval
Next

--
If this post helps click Yes
---------------
Jacob Skaria


"ExcelMonkey" wrote:

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


ExcelMonkey

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

"Jacob Skaria" wrote:

var1 = Range("A1:A10")
For Each strval In var1
Debug.Print strval
Next

--
If this post helps click Yes
---------------
Jacob Skaria


"ExcelMonkey" wrote:

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



All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com