gpt4 book ai didi

VBA:范围方法失败

转载 作者:行者123 更新时间:2023-12-03 03:47:11 25 4
gpt4 key购买 nike

我正在编写一段代码来选择我在某个范围内“打开”的工作簿的所有数据条目,但编译器在最后一行给出错误(设置范围 rng)

Dim wb As Workbook
Set wb = Workbooks.Open(Range("C2") & Range("C3"))
'here Range("C2") & Range("C3") contains the location of the file's path
Dim ws As Worksheet
Set ws = wb.ActiveSheet
Dim frow As Long
frow = ws.Range("A" & Rows.count).End(xlUp).Row
Dim rng As Range
Dim frow1 As Long
frow1 = ws.Cells(1, Columns.count).End(xlToLeft).Column
Set rng = wb.ActiveSheet.Range(Cells(1, 1), Cells(frow, frow1))

最佳答案

尝试:

Dim frow As Long
frow = ws.Range("A" & ws.Rows.count).End(xlUp).Row
Dim rng As Range
Dim fcol As Long
fcol = ws.Cells(1, ws.Columns.count).End(xlToLeft).Column
Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(frow, fcol))

请记住,如果您使用的是一组工作表,则必须在所有范围对象中引用它

关于VBA:范围方法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38305326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com