0

I have a worksheet (Sheet1) with 4 columns (A:D). In column A there is more than a 1000 lines of data and column D is blank. On Sheet2 I have a range called Indicators (B2:B11) which I need to copy into column D on Sheet1 and repeat the process in the next empty cell in column D all the way down to the last row of data in column A. This is the code I used to copy the range into column D but I have difficulty in repeating the process all the way down as I am not sure how to use the LastRow in this context.

Sub FillDownIndicators()
    Dim LastRow As Long
    LastRow = Sheet7.Cells(Rows.Count, 1).End(xlUp).Row

    Sheet3.Range("Indicators").Copy
    Sheet7.Range("D2").PasteSpecial Paste:=xlPasteValues
End Sub

In short once the range is copied into Column D (10 rows) it must be copied again in the next empty row in column D until the last row is reached in column A. Can someone please help?

0

2 Answers 2

0

trying to pastespecial the content of n cells into m cells wouldn't fill the whole wanted range

so I came up with the following

Option Explicit

Sub FillDownIndicators()
    Dim LastRow As Long

    With Sheet7
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        With .Range("D2:D" & LastRow)
            .ClearContents
            .Resize(Sheet3.Range("Indicators").Rows.Count).Value = Sheet3.Range("Indicators").Value
            With .SpecialCells(xlCellTypeBlanks)
                .FormulaR1C1 = "=R[-" & Sheet3.Range("Indicators").Rows.Count & "]C"
                .Value = .Value
            End With
        End With
    End With
End Sub

a more compact version of which would be:

Sub FillDownIndicators()
    With Sheet7.Range("D2:D" & Sheet7.Cells(Rows.Count, 1).End(xlUp).Row)
        .ClearContents
        .Resize(Sheet3.Range("Indicators").Rows.Count).Value = Sheet3.Range("Indicators").Value
        With .SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=R[-" & Sheet3.Range("Indicators").Rows.Count & "]C"
            .Value = .Value
        End With
    End With
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

@Louw, any feedback?
0

Just use your variable LastRow to build that range

Sheet7.Range("D2:D" & LastRow).PasteSpecial Paste:=xlPasteValues

3 Comments

trying to pastespecial the content of n cells into m cells wouldn't fill me the whole wanted range
@HTH True m needs to be n*x where x is an integer number. Then it should work. • In words: If you copy 10 cells then paste space needs to be 10, 20, 30, 40, … cells.
I think a preface/warning in the answer would be more appropriate then leaving this subject in comments. But that's just my opinion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.