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.
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.
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.