Do Until Loop + Then GoTo Skip

MatthewLane412

New Member
Joined
Aug 23, 2017
Messages
24
Hello,

I am still quiet new to VBA. I am working with a spreadsheet that requires me to Divide one column by another (eg. G2/F2, G3/F3, G4/F4...).
I'm having trouble getting "Then GoTo" skip to work in my code. If a cell in column "G" or column "F" has the variable "$0.00", i would like to skip to the next row.

Code:
Sub Division()

Dim finRow As String
finRow = Sheet2.Range("A6500").End(xlUp).Row


Dim I As Long
I = 2
Do Until I = finRow
If Sheet2.Range("G" & I).Value = "$0.00" Then GoTo Skip
Sheet2.Range("H" & I).Formula = "=G" & I & "/F" & I
Sheet2.Range("J" & I).Formula = "=I" & I & "/F" & I


Skip:
I = I + 1


Loop


End Sub

I appreciate any and all help.

Thanks,
Matt
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You are setting the value you want to cause a skip as the string "$0.00". If in fact that value is actually a number formatted as currency, then VBA will read it as 0.00 not "$0.00". So, replace that string with 0.00 and you should get a skip.

EDIT: Forgot to add that you can also fix your issue by changing this piece:

.Value = "$0.00" Then GoTo Skip

to this:

.Text= "$0.00" Then GoTo Skip
 
Last edited:
Upvote 0
Try this.
Code:
Sub Division()
Dim finRow As String
Dim I As Long

    finRow = Sheet2.Range("A6500").End(xlUp).Row

    I = 2
    
    Do Until I = finRow
        If Sheet2.Range("G" & I).Value <> 0 And Sheet2.Range("F" & I).Value <> 0 Then
            Sheet2.Range("H" & I).Formula = "=G" & I & "/F" & I
            Sheet2.Range("J" & I).Formula = "=I" & I & "/F" & I
        End If
        I = I + 1
    Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,785
Messages
6,174,537
Members
452,571
Latest member
MarExcelTips

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