我的意思是 在第七行找到带有今日日期的单元格之后 需要合并的区域是C3至C今日日期单元格
时间: 2024-03-30 11:35:25 浏览: 39
Sub MergeCells()
Dim Today As Date
Dim ColNum As Integer
Dim StartCell As Range
Dim EndCell As Range
Dim MergeRange As Range
'获取今日日期所在的列号
Today = Date
ColNum = Application.Match(Today, Range("1:1"), 0)
'计算需要合并的单元格范围
Set StartCell = Range("C3")
Set EndCell = Cells(3, ColNum)
Set MergeRange = Range(StartCell, EndCell)
'合并单元格并设置为居中对齐
With MergeRange
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
'对今日日期所在的单元格进行格式设置
Cells(3, ColNum).HorizontalAlignment = xlCenter
Cells(3, ColNum).VerticalAlignment = xlCenter
Cells(3, ColNum).Font.Bold = True
Cells(3, ColNum).Borders(xlEdgeBottom).LineStyle = xlContinuous
End Sub
根据你的最新的要求,我修改了代码,使得需要合并的区域为C3至C今日日期单元格。同时,在合并操作之后,我添加了对今日日期所在的单元格进行格式设置的代码,包括水平垂直居中对齐、加粗字体、以及添加底部边框。
阅读全文