We help IT Professionals succeed at work.

Excel VBA and cell value

TechPilot9133
on
I have a variable on a sheet that changes based on the row being read while the loop is executed.

Dim rowIndex as Integer
Dim SourceRange as Variant
SourceRange = ("A2")

In the loop I have this;
SourceRange = ("A") & rowIndex

The SourceRange is changing properly as the loop is executed, BUT,

I am trying to figure out of the variable SourceRange contains a string.  How do I get that value from SourceRange?  

Thanks.
Comment
Watch Question

Social distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Dim SourceRange as Range
SourceRange = ("A2")
MsgBox SourceRange.Value

Commented:
You could try something like this:-


If Application.WorksheetFunction.IsText(SourceRange) = True Then

----->do something here

End If

Hope this helps,
Matt

Commented:
Actually, this is better:-

If VarType(SourceRange) = vbString Then

---->Do something here

End If

Matt
TechPilot9133IS Operations Lead

Author

Commented:
That answer does exactly what I asked, but it does not help me whith what I am trying to do.  I will do further tests and hopefully formulate my question better.  Sometimes finding the proper way to ask the question is the harder than us newbs think. Thank you for the responses.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.