gpt4 book ai didi

VBA Excel - 选择左值的行=变量

转载 作者:行者123 更新时间:2023-12-04 21:24:08 24 4
gpt4 key购买 nike

这段代码有问题。没有错误,但似乎也没有做任何事情。
在我的工作表中,“M”列有一些以字母“T”开头的值,我想为这些值选择整行。提前致谢。

Sub trace1()
Dim trace As String
trace = "T"
Dim LR As Long, i As Long
LR = Range("M" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If Left(Range("M" & i).Value, 1) = trace Then Rows("i:i").Select
Next i
End Sub

最佳答案

以书面形式回答问题的一种可能方法:

Sub trace1()
Dim trace As String
trace = "T"
Dim LR As Long, i As Long

Dim SelectedRows As Range

LR = Range("M" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If Not SelectedRows Is Nothing Then
If Left(Range("M" & i).Value, 1) = trace Then Set SelectedRows = Union(SelectedRows, Rows(i))
Else
If Left(Range("M" & i).Value, 1) = trace Then Set SelectedRows = Rows(i)
End If
Next i
SelectedRows.Select 'Replace with .Copy if that's what you really wanted.
End Sub

关于VBA Excel - 选择左值的行=变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28862277/

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