情况:
在单元格"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
在图片中,必须删除红色圆圈中的数字 .
2 回答
在从下到上的工作方式:
也许这样的事情 . 它需要一些工作,因为如果两个值彼此相邻,或者第1列不包含值,它将失败 .