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
    1. Dim i, F1, F2, F3, F4, F5, F6 As Integer
    2. Set TsRng = Range("E3:J3")
    3. i = 1
    4. For Each Ts In TsRng
    5. If Ts.Value <> 0 Then
    6. "F" & i = Ts.Column
    7. i = i + 1
    8. End If
    9. 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
    1. Dim i As Integer, F(1 To 6) As Integer
    2. Set TsRng = Range("E3:J3")
    3. i = 1
    4. For Each Ts In TsRng
    5. If Ts.Value <> 0 Then
    6. F(i) = Ts.Column
    7. i = i + 1
    8. End If
    9. 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.

  • royUK

    Closed the thread.