[英]Autofill from Last row of a column till Last row of the entire sheet
Here I want to auto fill from B6 to B10.在这里,我想从 B6 自动填充到 B10。 B5 is the last row of Column B and A10 is the last row of entire sheet. B5 是 B 列的最后一行,A10 是整个工作表的最后一行。
Currently i am using the following code.目前我正在使用以下代码。
Dim Lastrow As Long
Dim Last As Long
Application.ScreenUpdating = False
Lastrow = Range("A" & Rows.Count).End(xlUp).row 'Last row from entire sheet
Last = Range("B" & Rows.Count).End(xlUp).Offset(1).row 'Last row of Column B +1
Range(Last & Lastrow).Formula = "4"
Application.ScreenUpdating = True
This works if i am using如果我正在使用,这有效
Range(B6:B & Lastrow).Formula = "4"
But This might not be helpful if the last rows changes但是如果最后一行发生变化,这可能没有帮助
Range(B6:B & Lastrow).Formula = "4"
改成
Range("B" & last & ":B" & Lastrow) = "4"
The next code will do what you required, referring the real last cell of the sheet , independent of the column where it exists:下一个代码将执行您需要的操作,引用sheet的真正最后一个单元格,独立于它所在的列:
Dim LastrowSh As Long, LastB As Long
LastrowSh = ActiveSheet.cells.SpecialCells(xlCellTypeLastCell).Row 'Last row from entire sheet
LastB = Range("B" & rows.count).End(xlUp).Offset(1).Row 'Last row of Column B + 1
Range("B" & LastB, "B" & LastrowSh).value = "4"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.