如何在Excel中通过他们的下一个可用值填充空白单元格?

我在Excel中有一些空白单元格,如图1所示。我想填充空白单元格,如图2所示。我的意思是,我想用下一个非空值填充空白单元格。

我想用一个命令来做,因为我有大量的数据。 任何人都可以帮助我做到这一点?

生态,

在MS Excel中,您可以使用“填充命令”自动填充相邻单元格中的数据。 请查看: https : //support.office.com/en-za/article/Fill-data-automatically-in-works-cells-74e31bdd-d993-45da-aa82-35a236c5b5db

你也可以用VBA来做到这一点。 http://www.extendoffice.com/documents/excel/771-excel-fill-blank-cells-with-value-above.html

我有一个“常规”的macros,我用它来复制数据的列,我已经调整了你,因为你想复制。 以下是VBA中的解决scheme:

Sub GEN_USE_Copy_Data_Up_Column() Dim screenRefresh As String, runAgain As String Dim lastRow As Long, newLastRow As Long Dim CopyFrom As Range Dim LastRowCounter As String screenRefresh = MsgBox("Turn OFF screen updating while macro runs?", vbYesNo) If screenRefresh = vbYes Then Application.ScreenUpdating = False Else Application.ScreenUpdating = True End If Dim EffectiveDateCol As Integer LastRowCounter = InputBox("What column has the most data (this info will be used to find the last used row). Use Letters") CopyAgain: With ActiveSheet 'lastRow = .Cells(.Rows.Count, LastRowCounter).End(xlUp).row lastRow = .UsedRange.Rows.Count End With ' THIS WILL ASK THE USER TO SELECT THE COLUMN TO COPY DATA DOWN MsgBox ("Now, you will choose a column, and that column's data will be pasted in the range below the current cell, to the next full cell") Dim Column2Copy As String Column2Copy = InputBox("What column (A,B,C, etc.) would you like to copy the data of?") Dim startCell As Range Set startCell = Cells(1048576, Column2Copy).End(xlUp) 'Cells(1, Column2Copy).End(xlDown).Select Do While startCell.Row > 1 If startCell.End(xlUp).Row = 1 Then newLastRow = 1 Else newLastRow = startCell.End(xlUp).Offset(1, 0).Row End If Set CopyFrom = startCell If startCell.Row Mod 5 = 0 Then Debug.Print startCell.Row Range(Cells(startCell.Row, Column2Copy), Cells(newLastRow, Column2Copy)).Value = CopyFrom.Value Set startCell = startCell.End(xlUp) 'startCell.Select Loop runAgain = MsgBox("Would you like to run the macro on another column?", vbYesNo) If runAgain = vbNo Then Cells(1, 1).Select If screenRefresh = vbYes Then Application.ScreenUpdating = True Else Application.ScreenUpdating = True End If Exit Sub ElseIf runAgain = vbYes Then GoTo CopyAgain End If End Sub 

由于这是一个“一般使用”的macros,我有提示要求你复制哪一列,以及是否要更新屏幕。 如果你不需要这些,让我知道,我可以删除/删除一些“绒毛”,离开macros观的主要部分。