Vba 填写一列';s具有相似值的空格

Vba 填写一列';s具有相似值的空格,vba,Vba,我正在尝试将excel文件添加到access数据库。我想让每个房间的名字都可以通过房间号来搜索。现在,如果查询房间号,它只会显示包含该房间号的行,即使房间号下面的行也包含该房间的数据。。。像这样: 所以,我想做的是编写一个脚本,扫描房间号列(第1列)。。。每次脚本到达一个唯一的房间号时,它用相同的房间号填充它下面的空白空间。 之后: 到目前为止,我已经写了这个测试脚本。。。但它似乎不起作用。。。有什么建议吗? 谢谢 假设MaterialDescription列在列表末尾之前不为空,并且roo

我正在尝试将excel文件添加到access数据库。我想让每个房间的名字都可以通过房间号来搜索。现在,如果查询房间号,它只会显示包含该房间号的行,即使房间号下面的行也包含该房间的数据。。。像这样:

所以,我想做的是编写一个脚本,扫描房间号列(第1列)。。。每次脚本到达一个唯一的房间号时,它用相同的房间号填充它下面的空白空间。

之后:

到目前为止,我已经写了这个测试脚本。。。但它似乎不起作用。。。有什么建议吗? 谢谢


假设MaterialDescription列在列表末尾之前不为空,并且roomNumberValue在第一行中不为空

如果所有列在列表末尾之前都有空字段,则可以选择For循环

counter = 'First row.

Do Until IsEmpty(Cells(counter, materialDescriptionColumn).Value)
    roomNumberValue = Cells(counter, roomNumberColumn).Value

    If roomNumberValue = "" Then
        Cells(counter, roomNumberColumn) = roomNumber
    Else
        roomNumber = roomNumberValue
    End If

    counter = counter + 1
Loop
counter = 'First row.

Do Until IsEmpty(Cells(counter, materialDescriptionColumn).Value)
    roomNumberValue = Cells(counter, roomNumberColumn).Value

    If roomNumberValue = "" Then
        Cells(counter, roomNumberColumn) = roomNumber
    Else
        roomNumber = roomNumberValue
    End If

    counter = counter + 1
Loop