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
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

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
75,915
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,953
Messages
5,545,145
Members
410,666
Latest member
Al3cs
Top