Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default String to Variant conversion

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:

For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c

The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?

Thanks,
Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default String to Variant conversion

I haven't used Harlan's function in a while, but are you sure that the
conversion to date isn't happening when you put the value back in the cell in
the worksheet?

If you know you want to return text, you could try this:

c.Value = "'" & xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))

Maybe it'll work ok for you.

Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:

For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c

The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?

Thanks,
Paul


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default String to Variant conversion

Read the value into a string before wrting to the cell

Dim TempString as string
For Each c In r
TempString = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
c.value = TempString
Next c

Also make surre you Excel4Macro is 2nd workbook is defined as a string

sub Excel4Macro(.....) as string

"Paul" wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:

For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c

The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?

Thanks,
Paul


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default String to Variant conversion

And if it does work ok, but you want to check before you convert to text:

Dim res as variant
res = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
if isdate(res) then
c.value = res
else
c.value = "'" & res
end if

(or add more significant checks.)

Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:

For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c

The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?

Thanks,
Paul


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default String to Variant conversion

Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:


For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c


The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?


On Oct 3, 6:08 pm, Dave Peterson wrote:
I haven't used Harlan's function in a while, but are you sure that the
conversion to date isn't happening when you put the value back in the cell in
the worksheet?


I use the debugger to step through the function, and the datatype on
c.Value is listed as "Variant/Double".


If you know you want to return text, you could try this:

c.Value = "'" & xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))

That does solve the date-conversion problem, but some of what I need
to get are actual numbers, so they shouldn't be turned to strings.
Thanks for the pointer, though, I think this gets me headed in the
right direction.

Thanks,
Paul



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default String to Variant conversion

"Paul" wrote:
I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:


For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c


The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?



On Oct 3, 6:08 pm, Joel wrote:
Read the value into a string before wrting to the cell

Dim TempString as string
For Each c In r
TempString = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
c.value = TempString
Next c


Thanks for the suggestion! That was the first thing I tried, and it
didn't work. When the string variable was assigned to c.value, did
the same thing as the direct assignment did before.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default String to Variant conversion

Maybe you could use that other suggestion.

Paul wrote:

Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:


For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c


The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?


On Oct 3, 6:08 pm, Dave Peterson wrote:
I haven't used Harlan's function in a while, but are you sure that the
conversion to date isn't happening when you put the value back in the cell in
the worksheet?


I use the debugger to step through the function, and the datatype on
c.Value is listed as "Variant/Double".


If you know you want to return text, you could try this:

c.Value = "'" & xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))

That does solve the date-conversion problem, but some of what I need
to get are actual numbers, so they shouldn't be turned to strings.
Thanks for the pointer, though, I think this gets me headed in the
right direction.

Thanks,
Paul


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default String to Variant conversion

This is what ended up working:

Dim temp as Variant
temp = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
If IsDate(temp) Then
c.value = "'" & temp
else
c.value = temp
end if

This would of course break the function if it were really supposed to
come through as a date, but for this application, it worked.

Thanks for the help!

On Oct 3, 6:09 pm, Dave Peterson wrote:
And if it does work ok, but you want to check before you convert to text:

Dim res as variant
res = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
if isdate(res) then
c.value = res
else
c.value = "'" & res
end if

(or add more significant checks.)



Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:


For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c


The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?


Thanks,
Paul


--

Dave Peterson



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default String to Variant conversion

Oftentimes, you really have to know your data to make those good
assumptions/decisions.



Paul wrote:

This is what ended up working:

Dim temp as Variant
temp = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
If IsDate(temp) Then
c.value = "'" & temp
else
c.value = temp
end if

This would of course break the function if it were really supposed to
come through as a date, but for this application, it worked.

Thanks for the help!

On Oct 3, 6:09 pm, Dave Peterson wrote:
And if it does work ok, but you want to check before you convert to text:

Dim res as variant
res = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
if isdate(res) then
c.value = res
else
c.value = "'" & res
end if

(or add more significant checks.)



Paul wrote:

I am using Harlan Grove's PULL function to grab data from other
spreadsheets, and it mostly works except that some strings that look
like dates get converted to numbers and therefore don't work with
VLOOKUP and the like. For example, "06-6107" gets changed to
1536728. It seems that this is happening in this bit of code:


For Each c In r
c.Value = xlapp.ExecuteExcel4Macro(b & c.Address(1, 1, xlR1C1))
Next c


The Value property is a Variant, so in the conversion the string is
interpreted as a date. Is there any way to force that to be converted
a Variant/String instead of Variant/Double?


Thanks,
Paul


--

Dave Peterson


--

Dave Peterson
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
String to Variant incorrect conversion Paul Excel Worksheet Functions 1 October 4th 07 01:11 AM
DIM Variant / String Helmut Excel Programming 0 August 9th 06 01:53 PM
Retain Variant / String value abc[_6_] Excel Programming 3 September 14th 05 07:50 AM
basic variant to array conversion Jeff Sward Excel Programming 1 January 26th 04 07:59 PM
Variant to String Chip Pearson Excel Programming 1 September 3rd 03 03:10 PM


All times are GMT +1. The time now is 10:59 AM.

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

About Us

"It's about Microsoft Excel"