Simple VBA code stalling on END IF?

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
I have a fairly simple code to copy some cells down after a countif = 0, but some reason this just stalls and when i hit escape it throws an error to the end if?

VBA Code:
    Sub NewSpineTable()
    
    Dim I As Long, LR As Long
    
    I = 2
    
    Do While Worksheets("Network Data").Cells(I, 14) <> ""
    
    
    LR = Worksheets("Spine Summary").Range("E" & Rows.Count).End(xlUp).Row
    
    If Application.WorksheetFunction.CountIf(Worksheets("Spine Summary").Range("D2:D" & LR), Worksheets("Network Data").Cells(I, 14) = 0) Then

    MsgBox "TRUE"

    LR = Worksheets("Spine Summary").Range("E" & Rows.Count).End(xlUp).Row + 1
    Worksheets("Spine Summary").Range("A2:T3").Copy Worksheets("Spine Summary").Range("A" & LR)
    Worksheets("Spine Summary").Range("A:" & LR & ":C" & LR + 1).ClearContents
    I = I + 1
    End If
    
    Loop

    End Sub
 
If Application.WorksheetFunction.CountIf(Worksheets("Spine Summary").Range("D:D"), Worksheets("Network Data").Cells(I, 14)) = 0 Then
Just noticed you have a bracket in the wrong place in the Countif line - it should be:

Code:
If Application.WorksheetFunction.CountIf(Worksheets("Spine Summary").Range("D:D"), Worksheets("Network Data").Cells(I, 14)) = 0 Then
ahhhhhhhhh thats it working! thanks alot, always the small stuff
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,216,028
Messages
6,128,400
Members
449,448
Latest member
Andrew Slatter

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