Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Keeps grabbing more than one cell/column | Excel Worksheet Functions | |||
Grabbing Formula Information from Another Cell | Excel Discussion (Misc queries) | |||
Grabbing data from a specific cell | Excel Worksheet Functions | |||
Grabbing text from just part of a cell | Excel Programming | |||
Grabbing the last Non-empty cell in a range | Excel Discussion (Misc queries) |