I have the following code that fills in the empty cells with the value of the cells above. This is done for columns B,L,C and G and the reference column used for the length of the range is column F. The code works fine as long as I have the book "Posbook" and the "PosSheet" open, however, it does not work if I view any other sheet. Can someone explain me why this is the case? I suspect that it has something to do with the Offset property. Can someone modify me this code so that PosBook does not always have to be the active sheet in order to work? Thanks!
HTML:
On Error Resume Next
With Workbooks(PosBook).Worksheets(PosSheet)
.Range("f5", Range("f" & Rows.Count).End(xlUp)).Offset(, -4).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Range("b5:b" & [f65536].End(xlUp).Row).Copy
.Range("B5").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
.Range("f5", Range("f" & Rows.Count).End(xlUp)).Offset(, 6).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Range("l5:l" & [f65536].End(xlUp).Row).Copy
.Range("L5").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
.Range("f5", Range("f" & Rows.Count).End(xlUp)).Offset(, -3).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Range("c5:c" & [f65536].End(xlUp).Row).Copy
.Range("c5").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
.Range("f5", Range("f" & Rows.Count).End(xlUp)).Offset(, 1).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Range("g5:g" & [f65536].End(xlUp).Row).Copy
.Range("g5").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
End With