Hi Experts,
I am trying to write code to clear the contents when workbook Open, but finding error on the same.
Hence, Request for your help for the same.
Below code and attached sheet for your ready reference.
Option Explicit Private Sub Workbook_Open() ' 206 Dim Rl As Long ' last used row in column A 'Dim R2 As Long ' last used row in column A Dim DelPrev As VbMsgBoxResult ' User input DelPrev = MsgBox("Delete previous day's Min1 & Max1 & Max2 & Min3?" & vbCr & _ "Press Cancel to not start the Timer.", _ vbQuestion Or vbYesNoCancel Or vbDefaultButton1, _ "Start new day?") If DelPrev <> vbCancel Then If DelPrev = vbYes Then With Worksheets("Sheet1") Rl = .Cells(.Rows.Count, "A").End(xlUp).Row .Range(.Cells(NwsFirstRow, NwsMax1), .Cells(Rl, NwsMax1)).ClearContents .Range(.Cells(NwsFirstRow, NwsMin1), .Cells(Rl, NwsMin1)).ClearContents '.Range(.Cells(NwsFirstRow, NwsMax2), .Cells(Rl, NwsMax2)).ClearContents '.Range(.Cells(NwsFirstRow, NwsMin3), .Cells(Rl, NwsMin3)).ClearContents With Worksheets("Sheet2") Rl = .Cells(.Rows.Count, "A").End(xlUp).Row .Range(.Cells(Nws1FirstRow, Nws1Max1), .Cells(Rl, Nws1Max1)).ClearContents .Range(.Cells(Nws1FirstRow, Nws1Min1), .Cells(Rl, Nws1Min1)).ClearContents '.Range(.Cells(NwsFirstRow, NwsMax2), .Cells(Rl, NwsMax2)).ClearContents '.Range(.Cells(NwsFirstRow, NwsMin3), .Cells(Rl, NwsMin3)).ClearContents End With End If SetTimer Set_Timer End If End Sub
Would really appreciate your response.
Regards,