Sub MarkTimeRange() Dim ws As Worksheet Dim startTime As String, endTime As String Dim taskName As String Dim colorRed As Integer, colorGreen As Integer, colorBlue As Integer Dim targetColumn As Long Dim startCell As Range, endCell As Range, cell As Range Dim selectedCell As Range ' 设置工作表 Set ws = ThisWorkbook.Sheets("Sheet1") ' 选择任务单元格(包含任务名称和填充颜色) OnErrorResumeNext Set selectedCell = Application.InputBox("请选择包含任务名称的单元格:", Type:=8) OnErrorGoTo0
If selectedCell IsNothingThen MsgBox "未选择任务单元格。" ExitSub EndIf