【发布时间】:2019-09-03 14:43:43
【问题描述】:
无法弄清楚如何水平填充 Excel 单元格...我在单元格“B2”中有“开始日期”,在单元格 B3 中有“结束日期”。
当我输入 2 个日期时,我只是用该范围内的日期填充所有单元格,但我垂直填充它们。我想水平填充它们
这是一张照片
"Data inizio" --> 开始日期 “数据正常”--> 结束日期
这是我到目前为止所做的事情
Sub FillCal()
' Disable screen updates (such as warnings, etc.)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim StartD As Date, EndD As Date
Dim prova As Integer
Dim rngMerge As Range, rngCell As Range, mergeVal As Range
Dim i As Integer
Dim wks As Worksheet
StartD = Foglio1.Cells(2, 2)
EndD = Foglio1.Cells(3, 2)
For Column = 1 To EndD - StartD
Cells(4, Column) = StartD + Column - 1
prova = Application.WorksheetFunction.WeekNum(StartD + Column - 1, 2)
Cells(5, Column).NumberFormat = prova
Cells(5, Column).Value = prova
Next Column
Set wks = ThisWorkbook.Sheets("Foglio1") ' Change Sheet1 to your worksheet
i = wks.Range("E1").End(xlDown).Row
Set rngMerge = wks.Range("E1:E" & i) ' Find last row in column A
With wks
' Loop through Column A
checkAgain:
For Each rngCell In rngMerge
' If Cell value is equal to the cell value below and the cell is not empty then
If rngCell.Value = rngCell.Offset(1, 0).Value And IsEmpty(rngCell) = False Then
' Define the range to be merged
' Be aware that warnings telling you that the 2 cells contain 2 differen values will be ignored
' If you have 2 different sums in column C, then it will use the first of those
' Set mergeVal = wks.Range(rngCell.Offset(0, 2), rngCell.Offset(1, 2))
' With mergeVal
' .Merge
' .HorizontalAlignment = xlCenter
' .VerticalAlignment = xlCenter
' End With
Range(rngCell, rngCell.Offset(1, 0)).Merge
rngCell.VerticalAlignment = xlCenter
GoTo checkAgain
End If
Next
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
你能发布一个预期输出的例子吗?
-
是的,当然对不起我忘了
-
@MiteNikolov 我提出了Answer,但粘贴您的完整代码将帮助我改进它..
-
我现在肯定会过去的! @Dorian
-
@MiteNikolov 我建议对您的帖子进行编辑,让 issue 出现,这样可以帮助其他用户;)。最诚挚的问候。