If you want to fill the blank cell in range with data from non blank cells above. Snapshot Below-
Step 1
Select the range.
Step 2
Press F5 ->Special -> choose Blanks
Step 3.
VBA Solution
Sub blank_cells_from_above()
Dim fillrng As Range, cl As Range
Dim i, j, s As Long
' change the range here
Set fillrng = Range("a1:a16")
For i = 1 To fillrng.Columns.Count
For j = 1 To fillrng.Rows.Count
If fillrng(j, i).Value <> vbNullString Then
s = j
Exit For
End If
Next j
If Application.WorksheetFunction.CountBlank(Range(Cells(fillrng(s, i).Row, fillrng(j, i).Column), Cells(fillrng(1, i).Row + fillrng.Rows.Count - 1, fillrng(s, i).Column))) >= 1 Then
Range(Cells(fillrng(s, i).Row, fillrng(j, i).Column), Cells(fillrng(1, i).Row + fillrng.Rows.Count - 1, fillrng(s, i).Column)).SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
End If
Range(Cells(fillrng(s, i).Row, fillrng(j, i).Column), Cells(fillrng(1, i).Row + fillrng.Rows.Count - 1, fillrng(s, i).Column)).Copy
Cells(fillrng(s, i).Row, fillrng(j, i).Column).Select
Selection.PasteSpecial Paste:=xlPasteValues
Next i
Application.CutCopyMode = False
End Sub
Subscribe to:
Post Comments (Atom)
Import data from SQL
Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...
-
If you want to add a new menu on mouse right click "Workbook Navigation showing you the list of all open workbooks and worksheets in ea...
-
Macro to Export Range in Json Format Option Explicit Sub export_in_json_format() Dim fs As Object Dim jsonfile Dim rangetoex...
No comments:
Post a Comment