本文介绍了在FBA中为FillDown动态设置范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim LastRow As Long, AddText As Long, SelectText As String
LastRowL = Range("L65536").End(xlUp).Row
AddText = LastRowL + 1
SelectText = "L" & AddText
Range(SelectText).Value = "Shipped"
Range("L2:L" & Range("A65536").End(xlUp).Row).FillDown 'How can I dynamically change the start range here? I want to start at SelectText.
感谢您帮助
Thank you for helping
推荐答案
- 激活
Sheet1
- 转到代码窗格(ALT + F11)
- 插入新模块
- 复制并粘贴下面的代码
Sub TestRange()
Range("A1") = "Test no. " & Rand()
End Sub
Sheet1
)并检查A1单元格值 Sheet2
)并再次运行宏Sheet1
) and check A1 cell valueSheet2
) and run macro again
结论:在使用上下文中编写代码,例如:
Conclusion: Write the code on context of usage, for example:
Sheet1.Range("A1") = Rand()
'or (better)
Worksheets("Sheet1").Range("A1") =Rand()
'or (best of)
ThisWorkbook.Worksheets("Sheet1").Range("A1") =Rand()
让我们回到你的问题...
我建议你编写自定义函数:
Let get back to your question...
I would suggest you to write custom function:
Function GetFirstEmptyRow(wsh As Worksheet, Optional sColName as String= "A") As Long
GetFirstEmptyRow = wsh.Range(sColName & wsh.Rows.Count).End(xlUp).Row +1
End Function
用法:
Usage:
Dim myWsh as Worksheet
Dim firstEmptyRow As Long
Set myWsh = ThisWorkbook.Worksheets("Sheet1")
firstEmptyRow = GetFirstEmptyRow(myWsh, "L")
myWsh.Range("L" & firstEmptyRow).Select
Set myWsh = Nothing
这篇关于在FBA中为FillDown动态设置范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!