Excel VBA runtime error 13

pedrofilipegomes

New Member
Joined
Jul 29, 2015
Messages
25
I have runtime error 13 in my file.

The error is in this code:
"
Dim i, k As Long
i = 0
k = 0
While Cells(i + 1, 1) <> ""
i = i + 1
If i = 1 Then
k = k + 1
Sheets("Final").Cells(k, 1) = Cells(i, 1)
Sheets("Final").Cells(k, 2) = Cells(i, 2)
Sheets("Final").Cells(k, 3) = Cells(i, 3)
Sheets("Final").Cells(k, 4) = Cells(i, 4)
Sheets("Final").Cells(k, 5) = Cells(i, 5)
Sheets("Final").Cells(k, 6) = Cells(i, 6)
Sheets("Final").Cells(k, 7) = Cells(i, 7)
Sheets("Final").Cells(k, 8) = Cells(i, 8)
Sheets("Final").Cells(k, 9) = Cells(i, 9)
ElseIf Cells(i, 11) <> "Não" And (Cells(i, 12) = "FUTURA" Or Cells(i, 12) = "CORRENTE" Or Cells(i, 12) = "PERMANENTE") Then
k = k + 1
Sheets("Final").Cells(k, 1) = Cells(i, 1)
Sheets("Final").Cells(k, 2) = Cells(i, 2)
Sheets("Final").Cells(k, 3) = Cells(i, 3)
Sheets("Final").Cells(k, 4) = Cells(i, 4)
Sheets("Final").Cells(k, 5) = Cells(i, 5)
Sheets("Final").Cells(k, 6) = Cells(i, 6)
If Sheets("Extract").Cells(i, 13) = "" Then
Else
Sheets("Final").Cells(k, 7) = Cells(i, 13)
End If
Sheets("Final").Cells(k, 8) = Cells(i, 8)
Sheets("Final").Cells(k, 9) = Cells(i, 9)
End If
Wend
"
The line where i have error is marked with red bold.

Anyone can help
me?

Thank's
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
No, please provide more details

When you run the code and it breaks, you are able to enter Debug mode. Do this and the row highlighted will be shown in yellow. At this point, what is the actual value of i? And what is the actual value of each cell in question?

To find these out, you can move the mouse over certain variables in your code. You can also use the Immediate window (Ctrl & G to show it) and ask questions by typing ? followed by a line of code, for example:
?i
?Cells(i, 11).value
 
Upvote 0
When i run the code and it breaks, the value of i is 2, Cells(i,11)="Não" and the value of Cells(i,12)= error 2042.

Can you help me please?
 
Upvote 0
Yes, the formula in cells(i,12) is currently returning a #N/A error. You need to either (1) fix the formula so that it doesn't do this, or (2) fix your code so that it knows what to do when trying to process an error value. Why is the formula returning an error?
 
Upvote 0
I don't know why the formula is giving an error. Doesn't always give an error when i run the macro. You can help me to change the formula in order to solve the error?

Thank's.
 
Last edited:
Upvote 0
Well yes but you have to give me a little more information...

You need to find out what the reason for the error is, or add a default value that simply overrides it. I wouldn't recommend simply hiding an error without understanding it, but you could use e.g. "=IFERROR(your formula,"error")

Otherwise, when your code breaks, you need to trace the N/A error back to it's source. What is the actual formula in that cell?
 
Upvote 0
Then I suspect one of the following:
- B2 contains #N/A
- B2 (or at least, the string in the first 3 characters) does not exist in your list at column C
- Column A contains #N/A
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top