0

我该如何进行这项工作?我试图让代码识别 C 列中最后使用的单元格并转到它。我在选择 rng1 中的单元格的最后一部分遇到问题

Sub jupiter3()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("Belmont")
Set rng1 = ws.Columns("c").Find("*", ws.[c1], xlValues, , xlByRows, xlPrevious)
If Not rng1 Is Nothing Then
    MsgBox "last cell is " & rng1.Address(0, 0)
Else
    MsgBox ws.Name & " columns A:B are empty", vbCritical
End If
Range("rng1.address(0, 0)").Select

结束子

4

2 回答 2

1

对我来说最简单的方法是使用这一行代码

Sheets("Belmont").Range("C" & Sheets("Belmont").Range("C" & Rows.Count).End(xlUp).Row).Select

但如果你想修改你的

Sub jupiter3()
    Dim ws As Worksheet
    Dim rng1 As Range
    Set ws = Sheets("Belmont")
    Set rng1 = ws.Columns("c").Find("*", ws.[c1], xlValues, , xlByRows, xlPrevious)
    If Not rng1 Is Nothing Then
        MsgBox "last cell is " & rng1.Address(0, 0)
        rng1.Select
    Else
        MsgBox ws.Name & " columns A:B are empty", vbCritical
    End If
End Sub

更改Range("rng1.address(0, 0)").Selectrng1.SelectRange(rng1.address).Select

于 2013-08-19T14:24:42.500 回答
0

rng1 变量被定义为一个范围,该范围由语言以不适合 range() 的方式解释。选择您想要定义一个字符串变量并像这样执行它。替换Range("rng.address(0,0)").Select

Dim zen as String
zen=rng.address(0,0)
range(zen).select
于 2013-08-19T14:08:22.947 回答