VBA / Code Ending Earlier than Desired

Cerestes

Board Regular
Joined
Jan 31, 2004
Messages
185
The below code scans through a list column of data in one sheet.
If it finds a match to a second sheet, it colors the match (and writes over a cell a few columns over).

The thinkg issue I'm having is with the "If c is nothing then end".

I just want it to end this function, (which is called from a larger one), but i think its ending my entire macro.

Thanks in advance for any help!

Code:
Sub Alterations()

Dim csr
Dim d As Range

    For Each d In Sheets("TempAlterations").Range("=OFFSET(TempAlterations!A2,0,0,COUNTA(TempAlterations!a2:A65000),1)")
        Set csr = d

            With Sheets("WorkHours").Range("=OFFSET(WorkHours!C2,0,0,COUNTA(WorkHours!C2:C65000),1)")
                Set c = .Find(csr, LookIn:=xlValues)
               If c Is Nothing Then End
                firstAddress = c.Address
                Do
                    If c.Value = d.Value Then
                    c.Interior.ColorIndex = 36
                    c.Interior.Pattern = xlSolid
                    c.Offset(columnoffset:=6).Value = d.Offset(columnoffset:=5).Value
                    c.Offset(columnoffset:=-1).Value = d.Offset(columnoffset:=4).Value
                    c.Offset(columnoffset:=-1).Interior.ColorIndex = 36
                    c.Offset(columnoffset:=-1).Interior.Pattern = xlSolid
                    
                    
                    
                    End If
                Set c = .FindNext(c)
                Loop While c.Address <> firstAddress
            End With
    Next d
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Try replacing the line with:

Code:
If c is nothing Then Exit Sub

and see if that makes a difference.

Richard
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,309
Office Version
  1. 365
Platform
  1. Windows
Cerestes

Using End will terminate all code that's running.

Using Richard's suggestion of Exit Sub should just end the code in that sub.
 

Forum statistics

Threads
1,144,700
Messages
5,725,829
Members
422,644
Latest member
BethGS

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
Top