我需要一些关于以下excel 2010 vba的帮助: 我想选择包含特定数字格式的所有单元格。单元格可以位于A列的任何位置。
欢迎任何想法。
提前谢谢!
答案 0 :(得分:0)
此代码:
Dim Tmp As String
Tmp = ""
For Each xx In Range("A1:A1000")
If (xx.NumberFormat = "0") Then
Tmp = Tmp & "," & xx.Address
End If
Next
Tmp = Mid(Tmp, 2)
Range(Tmp).Select
选择所有具有NumberFormat“0”的单元格...替换请求基础中的if stantement。
答案 1 :(得分:0)
这是使用Range.Find方法的方法
Option Explicit
Sub CellsWithNumberFormat()
Dim R As Range, C As Range
Const sFmt As String = "0.00" '<-- set to whatever numberformat you want
Dim colAddr As Collection
Dim sFirstAddress As String
Dim I As Long
Dim sTemp As String
Set R = Cells.Columns(1)
With Application.FindFormat
.NumberFormat = sFmt
End With
Set colAddr = New Collection
With R
Set C = .Find(what:="", LookIn:=xlValues, searchformat:=True)
If Not C Is Nothing Then
colAddr.Add Item:=C.Address
sFirstAddress = C.Address
Do
Set C = .Find(what:="", after:=C, searchformat:=True)
If C.Address <> sFirstAddress Then
colAddr.Add Item:=C.Address
End If
Loop Until sFirstAddress = C.Address
End If
End With
For I = 1 To colAddr.Count
sTemp = sTemp & "," & colAddr(I)
Next I
sTemp = Mid(sTemp, 2)
Range(sTemp).Select
End Sub