2014-04-15 125 views
0

我需要以下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」的細胞......如果替換爲stantement在您的要求的基礎。

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 
相關問題