Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50099

Syntax for .End(xlToRight)

$
0
0
I have a formula that works on a dynamic range. I cannot go to the last column and work back to the left, as data exists to the right of my dynamic range. Hence I want to use .End(xlToRight) to find the last column in the dynamic range. The below code is not working, can you suggest how to fix it?

Code:

Dim ecol As Long

    ecol = Range("F2", "F2".End(xlToRight))  'compile error: syntax error
    ecol = Range(("F2"), Range("F2").End(xlToRight)) 'Run-time error 13 Type mismatch
    ecol = Range("F2" & Columns.Count).End(xlToRight).Column  'No error, but the formula below returns #NAME? - I guess because I am not referencing row 2 in the Columns.Count section
   
    Range("C2").Formula = "=IF(COUNTIF(ecol,48)>0,(IF(COUNTIF(ecol,48)=COUNT(ecol),""Y"",""N"")),""N"")"
   
          ' This is the code created by recording keystrokes in a macro
    Range("F2").Select
    Range(Selection, Selection.End(xlToRight)).Select


Viewing all articles
Browse latest Browse all 50099

Trending Articles