Why do i get a runtime error in here?

Santino_X

New Member
Joined
May 1, 2011
Messages
15
Good night, I´m writing this code for a database but when i try to run it i keep getting runtime error in the line

Sub total()
Application.Calculation = xlManual
Dim ctotal As Integer, cposible As Integer, contador As Integer

For contador = 2 To 9551 'The quantity of items in my database
If Right(Range(contador, 6).Value, 3) = "c/3" Then 'C/3 is the value that 'might be at the end of a String value
ctotal = (Range(contador, 15).Value * 2) - Range(contador, 12).Value
cposible = ctotal / 3
cposible = ctotal - (cposible * 3)
If cposible < 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Range(contador, 22).Value = ctotal
End If
Next contador
Application.Calculation = xlAutomatic
End Sub


I keep getting the runtime error 1004 in this line
ctotal = (Range(contador, 15).Value * 2) - Range(contador, 12).Value

How can i fix that error?
Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Thanks, it worked fine, but when i try to ampliate the code, now i don't get errors but it doesn't make anything now and when i debug step by step, it gets into a loop...
Here is the code:

Sub Macroprota()

Dim ctotal As Integer, cposible As Integer,contador As Integer

For contador= 2 to 9551

If Right(Cells(contador, 6).Value, 3) = "c/3" Then
ctotal = Cells(contador, 15).Value * 2
ctotal = ctotal - Cells(contador, 12).Value
cposible = ctotal / 3
cposible = cposible * 3
cposible = ctotal - cposible
If cposible > 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(contador, 22).Value = ctotal

ElseIf Right(Cells(contador, 6).Value, 3) = "c/4" Then
ctotal = Cells(contador, 15).Value * 2
ctotal = ctotal - Cells(contador, 12).Value
cposible = ctotal / 4
cposible = cposible * 4
cposible = ctotal - cposible
If cposible > 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(contador, 22).Value = ctotal

Else
ctotal=Cells(contador,15).Value*2
ctotal=ctotal-Cells(contador,12).Value
EndIf
Next contador
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

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