lzl00
lzl00

Reputation: 21

VBA Expected:end of statement

I am trying to use a formula below and I keep on getting the expected end of statement error

 Worksheets("Report").Cells(8,3).Value="='DATA'!B"&lRow-2&"*'DATA'!D"&lRow-2

The error occurs on "*'DATA'!D"

Expected: End of statement

Upvotes: 1

Views: 163

Answers (2)

Pᴇʜ
Pᴇʜ

Reputation: 57683

When typing this line …

Worksheets("Report").Cells(8,3).Value="='DATA'!B"&lRow-2&"*'DATA'!D"&lRow-2

… into the editor make sure you have spaces in the correct places:

Worksheets("Report").Cells(8, 3).Value = "='DATA'!B" & lRow - 2 & "*'DATA'!D" & lRow - 2

Spacing is necessary because the & has 3 different meanings:

  1. Without space: Declare a number to be of type Long:
    2& means that 2 is of type Long.
    (also see Declaring variables).

  2. With spaces: Concatenate two strings:
    & with spaces means concatenate strings eg. TotalString = String1 & String2
    (also see &-Operator)

  3. &H specifying a hexadecimal number: Example &HF means hexadecimal F and Debug.Print &HF will output 15 which is the hexadecimal F converted into a decimal number.

Upvotes: 3

Wesley
Wesley

Reputation: 300

Worksheets("Report").Cells(8, 3).Value = "='DATA'!B" & lRow - 2 & "*'DATA'!D" & lRow - 2

Upvotes: 0

Related Questions