Hi everyone
I recorded a macro and was wondering if someone could help me refine it or show me a better way of doing it.
I need to insert an empty row 2.
Then I need to count the non empty cells from row 3 through to a row number whose value is 5 added to a number taken from cell A3 in Sheet3.
For example, if the value of A3 in Sheet3 is 13, then we need to go until row 18. I don't know how to code this, so I just typed A18 directly into the cell (which translated to R[16]C in my recorded example below).
Then I need to fill-drag the formula as far right as I need to go (determined by how many columns the current sheet has).
In the example below, I've gone up to Column M but in some cases, I may need to go up to Column AC.
Code:
Sub Macro1()
Rows("2:2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveCell.FormulaR1C1 = "=COUNTA(R[1]C:R[16]C)"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:M2"), Type:=xlFillDefault
Range("A2:M2").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
My "solution" is very clunky and there is likely a neater way around this so I apologise in advance for the code mess. I would need to learn how to code this nicely.
Can someone help me with this? Thanks!
Bookmarks