# Compile Error: Expected: line number or label or statement or end of statement

• Hi,
I am trying to pass the column value of cells with values not equal to zero to variables F1, F2, F3 , F4, F5 & F6. The code is as under;

Code
``````Dim i, F1, F2, F3, F4, F5, F6 As Integer
Set TsRng = Range("E3:J3")
i = 1
For Each Ts In TsRng
If Ts.Value <> 0 Then
"F" & i = Ts.Column
i = i + 1
End If
Next``````

I get a compile error message for the line "F" & i = Ts.column. Not sure what I am doing wrong here. Please help.
Thanks in advance.

• Re: Compile Error: Expected: line number or label or statement or end of statement

Is it really necessary to put the values into the variables
you can try putiing the values into a variant on a temp basis unntil you get an answer for this which will be easier if you r stuck and want to procede further with your development

• Re: Compile Error: Expected: line number or label or statement or end of statement

Hi ashu1990,

Thanks for your response.

Could you please elaborate on how to put the values into a variant? Sorry if I sound ignorant.

Cheers,

• Re: Compile Error: Expected: line number or label or statement or end of statement

You could use an array:

Code
``````Dim i As Integer, F(1 To 6) As Integer
Set TsRng = Range("E3:J3")
i = 1
For Each Ts In TsRng
If Ts.Value <> 0 Then
F(i) = Ts.Column
i = i + 1
End If
Next``````

Rory
Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

• Re: Compile Error: Expected: line number or label or statement or end of statement

Hi rory,
Thanks, that works!!! Much appreciated. :rock:

Cheers,

• I get same error while using the following code: Anyone to assist? Thanks in advance

• Your code works fine here once I replace the smart quotes around your file paths with regular quotes.

Rory
Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

• kamran1015

Welcome to the Forum

Please start your own post. Posting in another member's Thread is known as hijacking and is not allowed here. By all means add a link to a Thread that may be related to your question.

• kamran1015

Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post

All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.

How to use code tags

Just highlight all of the code and press the <> in the post menu above button to add the code tags.

Thanks.

I suggest you read the Forum Rules before posting again.

## Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!