Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Why does the macro gives compile error without any logical or syntax error in script?

$
0
0

I wrote a macro in excel vba. I am attaching the script below. I don't see any logical or syntax error in the macro but when I try to compile it, I get Compile error: Expected: To

Error

Below is my script attached

Sub Go()

Set ws = ActiveSheet

ws.Range("D:D").ClearContents
ws.Range("D:D").ClearFormats

ws.Cells(1, 4).Value = "Status"
ws.Cells(1, 4).Font.Bold = True

maxEntry = ActiveSheet.Cells(1048576, "A").End(xlUp).Row

pricePath = ws.Cells(2, 6).Value + "\" + ws.Cells(2, 7).Value
Set wbpp = Workbooks.Open(pricePath, UpdateLinks:=False)

ws.Activate

For i = 2 To maxEntry
    Path = ws.Cells(i, 1).Value + "\" + ws.Cells(i, 2).Value
    currSheet = ws.Cells(i, 3).Value
    Set wbp = Workbooks.Open(Path, UpdateLinks:=False)
    Set wbs = wbp.Sheets(currSheet)
    wbs.Activate
    wbs.Cells(1, 1).Value = "abc"

    wbp.Close Savechanges:=True
    ws.Activate
    ws.Cells(i, 4).Value = "Updated"
Next i

wbpp.Close Savechanges:=False

End Sub

After trying out various things I found out that the macro throws an error when my cursor is inside the macro sub, something like this

Cursor in the Sub

But when my cursor is outside the sub, the script runs fine

Out of Sub

Run Box

I don't remember this issue happening with my previous macros.

Any ideas why this is happening? Its really annoying to move cursor to the bottom to run every time I want to test/compile.


Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>