vba formula

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

vba formula

Post by VegasNath »

ws1b.Range("T" & row).Formula = "=MID(("C" & row), 10, 6)&"" - ""&J2"

Can anyone see what is wrong with my logic here? I have this inside a 'for next' loop but I am getting a syntax error.
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78789
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: vba formula

Post by HansV »

There shouldn't be a " before C, and there should be a & " after the word row in the formula:

ws1b.Range("T" & Row).Formula = "=MID((C" & Row & "), 10, 6)&"" - ""&J2"

BTW, "row" is not a very good name for a variable, since it is also the name of a built-in property. I'd use lngRow instead.
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: vba formula

Post by VegasNath »

Thanks Hans. The J2 also needs to be J & row. Why can I never work the syntax out with these?

Got there eventually.....

ws1b.Range("T" & row).Formula = "=MID((C" & row & "), 10, 6)&"" - ""&J" & row & ""
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78789
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: vba formula

Post by HansV »

You can omit the & "" at the end, it doesn't do anything: appending "" to a string doesn't alter that string.
Best wishes,
Hans