I have a macro below that’s used for converting/displaying data in a specific format. There are two triggers in the macro - it takes a specific course of action based on the value of another cell (AF1). If cell AF1 = 1 and it runs the code I have underneath that If statement, it takes a LONG TIME to run. If cell AF1 = 2 then the code runs in a reasonable amount of time.
If I don’t touch my computer at all, it takes at least 7 minutes to run. If I have a lot of applications going or try to do something else, it nearly freezes and takes much longer (just to note, the macro still runs successfully in that case).
Below is the code. I’m still a macro novice; is there more efficient code I can use that would produce the same results?
Code
Sub EISpricecheck()
'copies EIS tab pricing contents, pastes on CHECK tab. Here I will check to see if there are 1 or 2 sets of prices.
'This also concatenates discount key & applies/wknd/wkday values
'
Application.ScreenUpdating = False
'clear contents from "check" tab, but leaves formulas on right intact
Sheets("check").Select
Columns("A:AB").Select
Selection.ClearContents
'copies "EIS" tab data and pastes to "check" tab
Sheets("EIS").Select
Columns("A:AB").Select
Selection.Copy
Sheets("check").Select
Range("A1").Select
ActiveSheet.Paste
'check if there are 1 or 2 sets of prices:
'If 2 sets of prices, add concatenate formula in column D
If Sheets("check").Range("AF1") = 2 Then
'place concatenate formula in column D
Range("D1").Select
Do While IsEmpty(ActiveCell.Offset(0, 1)) = False
ActiveCell.FormulaR1C1 = ActiveCell.Offset(0, -3) & ActiveCell.Offset(0, -1)
ActiveCell.Offset(1, 0).Select
Loop
Range("D:D").EntireColumn.AutoFit
End If
'If 1 set of prices, replace "weekend" with "prices" and "weekday" with BLANK, then add concatenate formula in col D
If Sheets("check").Range("AF1") = 1 Then
Dim Target, cell As Range
Dim weekday, weekend, prices As String
weekday = "weekday"
weekend = "weekend"
Set Target = Sheets("check").Range(Range("C1"), Range("C65536").End(xlUp))
For Each cell In Target
If cell.Value = weekday Then cell.Value = ""
If cell.Value = weekend Then cell.Value = "prices"
Next cell
'add concat formula
Range("D1").Select
Do While IsEmpty(ActiveCell.Offset(0, 1)) = False
ActiveCell.FormulaR1C1 = ActiveCell.Offset(0, -3) & ActiveCell.Offset(0, -1)
ActiveCell.Offset(1, 0).Select
Loop
Range("D:D").EntireColumn.AutoFit
End If
Application.ScreenUpdating = True
End Sub
Display More