【发布时间】:2017-01-10 13:56:43
【问题描述】:
情况:
在单元格“A1”上,我的值为“1”
在单元格“A10”上,我的值为“2”
在单元格“A20”上,我的值为“3”
在单元格“A30”上,我的值为“4”
我想用 Excel VBA 做什么:
A1 和 A10 之间有空单元格。我希望 A2:A9 用 A10 的值填充,即“2”。
A10 和 A20 之间有空单元格。我希望 A11:19 用 A20 的值填充,即“3”。
问题是,A1 到 A30 的范围不固定。我想在整行中搜索不为空的单元格,并用已填充的上部单元格填充它们之间的单元格。
编辑:
为了解释更多,我有一个 Access 数据库,其中包含一个填充日期的表和一个填充数字的表。
我想向 Excel 表格制作报告。
Dim Daten As Variant
Daten = Array(rs!DatumJMinus8Monate, rs!DatumJ, rs!DatumI, rs!DatumH, rs!DatumG, rs!DatumF, rs!DatumE, rs!DatumD, rs!DatumC, rs!DatumB, rs!DatumA, rs!DatumA4Monate)
Dim Bedarfe As Variant
Bedarfe = Array(rs!BedarfJ8Monate, rs!BedarfJ, rs!BedarfI, rs!BedarfH, rs!BedarfG, rs!BedarfF, rs!Bedarfe, rs!BedarfD, rs!BedarfC, rs!BedarfB, rs!BedarfA, rs!BedarfA, "")
Dim neuereintrag As Boolean
bedarfindex = 0
For Each element In Daten
i = 7
For jahre = 1 To 10
If Cells(1, i + 1) = Year(element) Then
For monate = 1 To 12
If Cells(2, i + monate) = Month(element) Then
Cells(zeile, i + monate) = Bedarfe(bedarfindex)
Cells(zeile, i + monate).Font.Bold = True
bedarfindex = bedarfindex + 1
neuereintrag = True
ElseIf IsEmpty(Cells(zeile, i + monate)) Or neuereintrag = True Then
Cells(zeile, i + monate) = Bedarfe(bedarfindex)
neuereintrag = False
End If
Next monate
End If
i = i + 12
Next jahre
Next element
图中红圈内的数字必须删除。
【问题讨论】:
-
你说过你尝试了很多方法,你能展示一些你做了什么吗?这不是“我的代码”网站,但如果您给我们一些帮助,我们将帮助您实现目标!
-
编辑您的问题并在其中添加您的
code。 -
我会在几分钟内完成,需要一些时间
-
代码是德文的,你要我把变量名改成英文吗?
-
On the Cell "A30" i have the value "4"- 这个值会被复制到第 1048576 / 65536 行吗?