【发布时间】:2015-02-10 07:07:14
【问题描述】:
我对 VBA 相当陌生,并且在基本语法方面遇到了一些一般性障碍。我正在使用下面的代码来修剪我目前正在处理的 ActiveSheet 的前导空格和颜色代码。
我有另一个名为“国家/地区”的工作表,我想将相同的逻辑应用于我正在使用的当前工作表。我也很难使用最有效的代码来查找任何值为“AcctTotal”、“CurrTotal”和“BravoTotal”的单元格(大约有 14,000 行数据)。我目前正在突出显示整个电子表格并使用“UsedRange”来查找这些单元格。
总结一下: 我想在两个工作表中修剪前导空格并用颜色编码“AcctTotal”、“CurrTotal”和“BravoTotal”的任何值:“Currency”和“Country”
Sub ColorCodeCurrency()
Dim r As Range
For Each r In Selection
If r.Value = " AcctTotal" Then
r.Value = LTrim(r.Value)
Intersect(r.EntireRow, ActiveSheet.UsedRange).Interior.ColorIndex = 15
End If
Next r
Dim s As Range
For Each s In Selection
If s.Value = " CurrTotal" Then
s.Value = LTrim(s.Value)
Intersect(s.EntireRow, ActiveSheet.UsedRange).Interior.ColorIndex = 40
End If
Next s
Dim t As Range
For Each t In Selection
If t.Value = " BravoTotal" Then
t.Value = LTrim(t.Value)
Intersect(t.EntireRow, ActiveSheet.UsedRange).Interior.ColorIndex = 35
End If
Next t
结束子
【问题讨论】: