Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用VBA自动填充_Vba_Excel - Fatal编程技术网

用VBA自动填充

用VBA自动填充,vba,excel,Vba,Excel,我正在尝试使用宏自动填充,但它不起作用。。。将只填充H2和I2单元格,其余为空白。我的代码怎么了 Sub company() Dim LastRow As Long With Sheets("Combined") LastRow = .Cells(Rows.Count, "H").End(xlUp).Row .Range("H2:H" & LastRow).Value = 0 LastRow = .Cells(Rows.Count, "I").End(xl

我正在尝试使用宏自动填充,但它不起作用。。。将只填充H2和I2单元格,其余为空白。我的代码怎么了

Sub company()
Dim LastRow As Long
    With Sheets("Combined")
    LastRow = .Cells(Rows.Count, "H").End(xlUp).Row
    .Range("H2:H" & LastRow).Value = 0
    LastRow = .Cells(Rows.Count, "I").End(xlUp).Row
    .Range("I2:I" & LastRow).Value = 1
    End With

End Sub

如果在H列中只有H2被填充,那么LastRow将是2。您希望数据填充到哪里?此外,您使用
.Value2
而不是
.Value
是否有原因?最后-不需要用引号将0和1括起来,除非出于任何原因希望它们被解释为文本。您如何知道在哪一行中停止?您在其他列中有数据吗?如果a列中有一整列数据(例如),请将
单元格(Rows.Count,“H”
更改为
单元格(Rows.Count,“a”
@FernandoJ.Rivera),它成功了!非常感谢!!!现在要学究了…这不是真正的自动填充。
.Range(“I1”)。autofill.Range(“I1:I”和LastRow)
将是自动填充(尽管基于单个数字,但给出了相同的结果)。