0

I am a Programmer but never use VBA. I am taking over someone's old script and it keeps failing at a certain point with a Run-Time Error.

enter image description here

The Debugging report is here:

enter image description here

Please let me know if you need more code. I have tried to change currRow to Long, single, double, string none work. Below is a quick glimpse of the sheet that is failing. The top row is row one.

enter image description here

8
  • What are you trying to do with Not Cells(currRow, 20)? Note: screenshots of code aren't allowed, please edit your question with the code as text. Commented Jul 9, 2021 at 15:45
  • @BigBen not sure, I inherited this script. I am not even sure what the index is referencing (currRow, 20) = (row, column)? Commented Jul 9, 2021 at 15:48
  • 1
    Yes, it's row, column, but the real problem is Not. Any chance it's missing an IsEmpty? Probably this is a poor attempt to find the last row. Commented Jul 9, 2021 at 15:49
  • 2
    Side notes: don't use Integer, use Long. Commented Jul 9, 2021 at 15:53
  • 1
    I'm guessing it should be Not IsEmpty(Cells(currRow, 20)). Commented Jul 9, 2021 at 15:55

1 Answer 1

3

My guess is that this is missing an IsEmpty:

Do While Not IsEmpty(Cells(currRow, 20))

However, this loop is a very inefficient way to find the last row.

I believe something like this is what you want:

With ActiveWorkbook.Worksheets("Analysis")
    Dim lastRow As Long
    lastRow = .Cells(.Rows.Count, 20).End(xlUp).Row

    .Range(lastRow + 1 & ":" & .Rows.Count).ClearContents
End With

Additionally:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.