Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Type Mismatch Error

I am receiving a type mismatch error on the below code.

Range("SUB!D" & i).Value = Range("SUB.CSV!D" & x) + Str(Range("SUB.CSV!F" &
x)) + " /" + Range("SUB.CSV!E" & x)

The problem is the Range("SUB.CSV!D" & x) piece of the code can sometimes
have characters, sometimes it has numbers, it varies. Is there a way around
this?

Thank you



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Type Mismatch Error

Hi
try something like the following:

sub foo()
dim wks1 as worksheet
dim wks2 as worksheet
set wks1 = worksheets("SUB")
set wks2 = worksheets("SUB.CSV")

with wks2
wks1.range("D"&i).value = Cstr(.Range("D"&x).value) & _
cstr(.Range("F"&x).value) & "/" & Cstr(.range("E" & x).value)

end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


SRS Man wrote:
I am receiving a type mismatch error on the below code.

Range("SUB!D" & i).Value = Range("SUB.CSV!D" & x) +
Str(Range("SUB.CSV!F" & x)) + " /" + Range("SUB.CSV!E" & x)

The problem is the Range("SUB.CSV!D" & x) piece of the code can
sometimes have characters, sometimes it has numbers, it varies. Is
there a way around this?

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Type Mismatch Error

Thank you Frank.

I already had the code in place, the CSTR did the trick.
Is there a way to format the "F" range, so it is always five digits using
code? It is on the spreadsheet, but that doesn't come over.


"Frank Kabel" wrote in message
...
Hi
try something like the following:

sub foo()
dim wks1 as worksheet
dim wks2 as worksheet
set wks1 = worksheets("SUB")
set wks2 = worksheets("SUB.CSV")

with wks2
wks1.range("D"&i).value = Cstr(.Range("D"&x).value) & _
cstr(.Range("F"&x).value) & "/" & Cstr(.range("E" & x).value)

end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


SRS Man wrote:
I am receiving a type mismatch error on the below code.

Range("SUB!D" & i).Value = Range("SUB.CSV!D" & x) +
Str(Range("SUB.CSV!F" & x)) + " /" + Range("SUB.CSV!E" & x)

The problem is the Range("SUB.CSV!D" & x) piece of the code can
sometimes have characters, sometimes it has numbers, it varies. Is
there a way around this?

Thank you



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Type Mismatch Error

Hi
change the line
wks1.range("D"&i).value = Cstr(.Range("D"&x).value) & _
cstr(.Range("F"&x).value) & "/" & Cstr(.range("E" & x).value)

to
wks1.range("D"&i).value = Cstr(.Range("D"&x).value) & _
format(.Range("F"&x).value,"00000") & "/" & Cstr(.range("E" &
x).value)


--
Regards
Frank Kabel
Frankfurt, Germany


SRS Man wrote:
Thank you Frank.

I already had the code in place, the CSTR did the trick.
Is there a way to format the "F" range, so it is always five digits
using code? It is on the spreadsheet, but that doesn't come over.


"Frank Kabel" wrote in message
...
Hi
try something like the following:

sub foo()
dim wks1 as worksheet
dim wks2 as worksheet
set wks1 = worksheets("SUB")
set wks2 = worksheets("SUB.CSV")

with wks2
wks1.range("D"&i).value = Cstr(.Range("D"&x).value) & _
cstr(.Range("F"&x).value) & "/" & Cstr(.range("E" & x).value)

end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


SRS Man wrote:
I am receiving a type mismatch error on the below code.

Range("SUB!D" & i).Value = Range("SUB.CSV!D" & x) +
Str(Range("SUB.CSV!F" & x)) + " /" + Range("SUB.CSV!E" & x)

The problem is the Range("SUB.CSV!D" & x) piece of the code can
sometimes have characters, sometimes it has numbers, it varies. Is
there a way around this?

Thank you


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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Why type mismatch - R/T error 13 Jim May Excel Discussion (Misc queries) 5 January 9th 05 06:45 PM
Type Mismatch error Mike Excel Programming 3 January 17th 04 04:23 PM
Type Mismatch Error Need Help Ray Batig Excel Programming 1 September 16th 03 12:57 AM
Type mismatch error Stuart[_5_] Excel Programming 0 August 16th 03 05:20 PM


All times are GMT +1. The time now is 07:02 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"