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 have added the shape in the sheet and now you want to change it color , text , font size ,etc using VBA. Snapshot below Code- Su...
-
If you want to add a new pop up button on mouse right click menu and as soon as you click on it . It shows you multiple buttons with macro a...
No comments:
Post a Comment