Copy cell value to all cells below it

2019-09-20 05:11发布

I don't know how to write a macro that designates a cell within a column as a "master cell" (editable) copy that cells value to all the cells below it in that column, until it reaches a blank/clear formatted cell in column A. So I want it to look at column A to know when to stop copying the cell values in whichever column.

That is, Cell "C5" will be a master cell, the macro will copy it's value from "C6:C" but looking at column A's cell values to see if it has nothing in it and there's no formatting such as color fill, etc. and instead of the macro continuing on in column C to infinity (maximum increment for Excel) it will stop at A column's first blank cell row.

1条回答
Root(大扎)
2楼-- · 2019-09-20 05:51
Sub Example()
    Dim MasterValue As String
    Dim StopRow As Long
    Dim i As Long

    'Get the master value
    MasterValue = Range("C5").Value

    'Get the first blank cell in column A
    StopRow = Range("A1").End(xlDown).Row

    'Start at row 6 and continue to the "Stop Row"
    For i = 6 To StopRow
        'Set every cell from row 6 in column 3 to the "Master Value"
        Cells(i, 3).Value = MasterValue
    Next
End Sub
查看更多
登录 后发表回答