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.
vba formula
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
vba formula
![Wales :wales:](./images/smilies/Wales.gif)
![UK :uk:](./images/smilies/UK.gif)
There's no place like home.....
-
- Administrator
- Posts: 78789
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vba formula
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.
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
Hans
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Re: vba formula
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 & ""
Got there eventually.....
ws1b.Range("T" & row).Formula = "=MID((C" & row & "), 10, 6)&"" - ""&J" & row & ""
![Wales :wales:](./images/smilies/Wales.gif)
![UK :uk:](./images/smilies/UK.gif)
There's no place like home.....
-
- Administrator
- Posts: 78789
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vba formula
You can omit the & "" at the end, it doesn't do anything: appending "" to a string doesn't alter that string.
Best wishes,
Hans
Hans