我已经搜索并尝试了有关此问题的大量解决方案。但是没有一个能奏效。因此,我试图在此处附加excel文件。
我的问题是:
Column A
1324
12312
14
4323
12
11234
我希望B看起来像这样:
Column B
1324
12312
14
4323
12
11234
看起来很简单。但这是行不通的,因为“空白”单元格实际上并没有显示为空白。而且我找不到摆脱它们的方法。我附上excel文件供您参考。
Excel文件: https://drive.google.com/open?id=1PDskY1GJKYhzzj905KrX988F8tTaNQSs
答案 0 :(得分:0)
我相信以下内容将达到您想要的结果,只需在命令按钮下复制代码即可。
这将通过第1行循环到A列的Last,如果单元格不是空白,它将把值传递到B列的下一个空闲行:
Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
'declare and set the worksheet you are working with, amend as required
LastRowA = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data on Column A
For i = 1 To LastRowA
'loop from row 1 to Last
LastRowB = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row + 1
'get the last row with data on Column B and offset by one (next empty row)
If ws.Cells(i, "A").Value <> "" Then ' if Column A's value is not empty
ws.Cells(LastRowB, "B").Value = ws.Cells(i, "A").Value 'pass that value to the next available row on Column B
End If
Next i
End Sub