Better Code for Cell Comparison (Dates)

jonyskids

New Member
Joined
Feb 15, 2012
Messages
15
I am pretty new to VBA for Excel and have written some code that works but runs slow. I am looking for suggestions as to how to make it more efficient.

Code:
For Each Cell In Worksheets("Sales Forecast").Range("B1,J1,R1,Z1,AH1,AP1,AX1,BF1,BN1,BV1,CD1,CL1,CT1")
On Error Resume Next
Err.Clear
Result = Application.WorksheetFunction.VLookup(Cell.Value, Worksheets("Promos-Adjustments").Range("C6:C18"), 1, False)
If Err.Number = 0 Then
    
      
    Worksheets("Sales Forecast").Cells(62, Cell.Column).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 1).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 2).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 3).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 4).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 5).Locked = False
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 6).Locked = False
    
        
Else
    Worksheets("Sales Forecast").Cells(62, Cell.Column).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 1).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 2).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 3).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 4).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 5).ClearContents
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 6).ClearContents
    
    Worksheets("Sales Forecast").Cells(62, Cell.Column).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 1).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 2).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 3).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 4).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 5).Locked = True
    Worksheets("Sales Forecast").Cells(62, Cell.Column + 6).Locked = True

    
End If
 Next Cell

This range is column heading dates:
Range("B1,J1,R1,Z1,AH1,AP1,AX1,BF1,BN1,BV1,CD1,CL1,CT1")

This range is "user inputted" dates::
Worksheets("Promos-Adjustments").Range("C6:C18")

Any suggestion are appreciated.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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