简体   繁体   English

对象_global的方法范围失败

[英]Method range of object _global failed

I simply want to use the value in C2 to populate the rest of column C with the same value all the way to the bottom of the data in the sheet. 我只是想使用C2中的值,以相同的值填充C列的其余部分,一直到工作表中数据的底部。

Sub Testfill1()
'
' Testfill1 Macro
'

'
    Sheets(1).Select
    lngEndRow = lastCellBlock

    Range("C2:C" & lngEndRow).FormulaR1C1 = "1"
End Sub

I simply want to use the value in C2 to populate the rest of column C with the same value all the way to the bottom of the data in the sheet. 我只是想使用C2中的值,以相同的值填充C列的其余部分,一直到工作表中数据的底部。

This should do what you want: 这应该做您想要的:

Sub FillDown()
    Range("C2", "C" & rows.Count).FillDown
End Sub

If that doesnt work or doesnt answer your question let me know 如果这样不起作用或无法回答您的问题,请告诉我

This will find the last row in column C with a value and copy whatever is in C2 down to that cell. 这将在C列中找到具有值的最后一行,并将C2中的所有内容复制到该单元格中。

Sub CopyDown()
    Dim ws As Worksheet
    Dim lastRow As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")
    lastRow = ws.Range("C" & ws.Rows.Count).End(xlUp).Row

    ws.Range("C2").Copy ws.Range("C2:C" & lastRow)

End Sub

Try below code 试试下面的代码

Sub Testfill1()

    Dim lastRow As Long
    With Sheets("sheet1")
        lastRow = .Range("C" & .Rows.Count).End(xlUp).Row
        .Range("C2:C" & lastRow).FormulaR1C1 = "1"
    End With

End Sub

I simply want to use the value in C2 to populate the rest of column C with the same value all the way to the bottom of the data in the sheet. 我只是想使用C2中的值,以相同的值填充C列的其余部分,一直到工作表中数据的底部。

I am interpreting "bottom of the data" to mean the extents of your data and not the absolute bottom of the worksheet (the latter being C1048576 in Excel 2007/2010/2013). 我将“数据底部”解释为数据的范围,而不是工作表的绝对底部(后者在Excel 2007/2010/2013中为C1048576)。 It isn't clear on whether C2 contains a formula or not so that should likely be left alone and its value stuffed into the remaining cells from C3 down to the extents of the data. 目前尚不清楚C2是否包含公式,因此应该将其单独放置,并将其值从C3填充到其余单元格直至数据范围。

  Range("C3:C" & cells(rows.count, 3).end(xlUp).row) = Range("C2").value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM