gpt4 book ai didi

VBA 搜索值并更改第 2 行的格式

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

有人可以帮我处理下面的vba吗?我想要实现的是在列中搜索一串文本,如果它符合我的条件,则更改动态范围的格式。我很难弄清楚如何使该范围动态化。总是匹配字符串 + 2 的行。

这是我到目前为止所得到的:

Sub FormatPercentages()
Dim RowToTest As Long


For RowToTest = Cells(Rows.count, 27).End(xlUp).Row To 2 Step -1

With Cells(RowToTest, 27)
If .Value Like "*Efficiency*" _
Then _
Range("AD129:AS131").NumberFormat = "0%"
End With

Next RowToTest

End Sub

我需要范围部分的帮助: 范围("AD129:AS131").NumberFormat = "0%"
我认为它应该是这样的,尽管我知道它写得不好(AD & "N": & AD.xlToRight & "N"+2)。其中 N 是与字符串 Efficiency 匹配的行号。

谢谢,
C

最佳答案

试试 Resize属性(property):

Range("AD" & RowToTest).Resize(3, 1).NumberFormat = "0%"

或者,
Cells(RowToTest, 27).Resize(3, 1).NumberFormat = "0%"

关于VBA 搜索值并更改第 2 行的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45242857/

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