Type Mismatch Error

  • Thread starter Thread starter SRS Man
  • Start date Start date
S

SRS Man

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
 
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
 
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.
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top