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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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.
 
Upvote 0

Forum statistics

Threads
1,222,142
Messages
6,164,169
Members
451,880
Latest member
2da

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