ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with Grabbing Cell Value from Range (https://www.excelbanter.com/excel-programming/410645-help-grabbing-cell-value-range.html)

chris c

Help with Grabbing Cell Value from Range
 
This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.

FSt1

Help with Grabbing Cell Value from Range
 
hi
looks like your are trying to set a string as an object. can't do this.
try this
Sub tttest()
Dim strDb As Range
Set strDb = Sheets("sheet1").Range("C2")'range is an object
Dim strDBString As String
strDBString = strDb.Text 'string is not an object
MsgBox strDBString
End Sub

regards
FSt1

"Chris C" wrote:

This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.


Office_Novice

Help with Grabbing Cell Value from Range
 
http://www.erlandsendata.no/english/...php?t=envbadac
or
http://www.carlprothman.net/Default....orMicrosoftJet

Good sources for This kind of thing good luck

"Chris C" wrote:

This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.


chris c

Help with Grabbing Cell Value from Range
 
The issue is that it's throwing me an "Object Required" error. I understand
that it's not being assigned properly, but the API seems to indicate the the
"Text" property of the Range object is what should be used for grabbing the
value from the range.

I looked to make sure that the strDb is getting assigned a value, and it is,
and it's the exactly the value I'm looking for.

"FSt1" wrote:

hi
looks like your are trying to set a string as an object. can't do this.
try this
Sub tttest()
Dim strDb As Range
Set strDb = Sheets("sheet1").Range("C2")'range is an object
Dim strDBString As String
strDBString = strDb.Text 'string is not an object
MsgBox strDBString
End Sub

regards
FSt1

"Chris C" wrote:

This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.


FSt1

Help with Grabbing Cell Value from Range
 
hi
i suspected that that was the error you were getting.
you "set" objects to equal somthing using the set command.
but a string is not an object so you just have it equal somthing WITHOUT the
set command. this is why your are getting the error. a string is not an
object, more like a value. a range is an object that contains the value.
other than that, your code works fine.

regards
FSt1


"Chris C" wrote:

The issue is that it's throwing me an "Object Required" error. I understand
that it's not being assigned properly, but the API seems to indicate the the
"Text" property of the Range object is what should be used for grabbing the
value from the range.

I looked to make sure that the strDb is getting assigned a value, and it is,
and it's the exactly the value I'm looking for.

"FSt1" wrote:

hi
looks like your are trying to set a string as an object. can't do this.
try this
Sub tttest()
Dim strDb As Range
Set strDb = Sheets("sheet1").Range("C2")'range is an object
Dim strDBString As String
strDBString = strDb.Text 'string is not an object
MsgBox strDBString
End Sub

regards
FSt1

"Chris C" wrote:

This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.


DMoney

Help with Grabbing Cell Value from Range
 
try this

dim sftDB as string
sheets("Dashboard").select
strDB=range("c2").value


"Chris C" wrote:

This is the code I have:

' Grab the database name
Dim strDb As Range
Set strDb = Worksheets("Dashboard").Range("C2")
Dim strDBString As String
Set strDBString = strDb.Text

The range is assigned without a problem; however, extracting the actual text
value seems never to work. Can anyone clarify exactly how this should happen?

My underlying motivation is to pull a cell value in VBA, and then use that
in a SQL query within VBA as well.



All times are GMT +1. The time now is 01:12 AM.

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