Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeps grabbing more than one cell/column confused Excel Worksheet Functions 1 March 11th 09 03:42 PM
Grabbing Formula Information from Another Cell RJB Excel Discussion (Misc queries) 7 September 13th 08 06:03 PM
Grabbing data from a specific cell *Kenneth* Excel Worksheet Functions 2 March 18th 08 10:31 PM
Grabbing text from just part of a cell Mary T[_2_] Excel Programming 2 January 5th 06 07:01 PM
Grabbing the last Non-empty cell in a range Arlen Excel Discussion (Misc queries) 2 January 22nd 05 05:15 PM


All times are GMT +1. The time now is 05:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"