2014-04-13 100 views
0

我正在尋找通過特定範圍的單元格進行排序並查看該單元格的LEN(gth)是否等於20.如果是,我想清除所述單元格的內容並移動到下一個單元格,直到它們全部被評估爲止。如果匹配條件清除表格的單元格值

我有這個報告是從一個網站拉出來的,並出口到excel和煩惱是0.0%,顯示爲英鎊符號(#x的20)。我嘗試了其他搜索字符串的宏,它完全忽略了0%,一個常數是每個出現的單元格長度都是20個字符。

應該發生的是我:

1 Searching C3:U20 
2 for cell.len = 20 
3 if activecell = matches criteria 
4 then clear.contents 
5 Goto 1 until all activecells with a len of 20 are cleared 

謝謝您可以提供任何幫助。

* 編輯 * 因爲我無法使這項工作,我用了一個 「解決」。這是效率低下,因爲它只用在一張小桌子上,它並不重要。我只需要在「三個」單獨的腳本中執行此操作。我發現如果我將百分比格式的範圍轉換爲常規,我只能將溢出數字看作字符串。然後,一旦被「清除」我只是重新轉換這些列的百分比格式:

Sub sub_ConvertToGeneral() 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
'''' Convert the Percentage Columns to General Format 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 

    Columns("F:F").Select 
    'Application.FormulaBarHeight = 2 
    Range("F:F,H:H,L:M,O:O,S:S,U:U").Select 
    Range("U1").Activate 
    Selection.NumberFormat = "General" 
    'Selection.NumberFormat = "0.00%" 
    Range("A1:B1").Select 
End Sub 

Sub sub_Overflow() 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
'''' Find Overflow and delete every instance of it 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 

    Dim FindString As String 
    Dim rng As Range 
    FindString = "2.6965E+308" 
50 
    If Trim(FindString) <> "" Then 
     With Sheets("Main Import").Range("C1:U20") 
      Set rng = .Find(What:=FindString, _ 
          After:=.Cells(.Cells.Count), _ 
          LookIn:=xlValues, _ 
          LookAt:=xlWhole, _ 
          SearchOrder:=xlByRows, _ 
          SearchDirection:=xlNext, _ 
          MatchCase:=False) 
      If Not rng Is Nothing Then 
       Application.Goto rng, True 
       ActiveCell.ClearContents 
       Do 
       Set rng = .FindNext(rng) 
       GoTo 50 
       Loop While Not rng Is Nothing 
       Else 
      End If 
     End With 
    End If 
    Range("A1").Select 
End Sub 

Sub sub_ConvertToPercentage() 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
'''' Convert the General Columns to Percentage 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 

    Columns("F:F").Select 
    'Application.FormulaBarHeight = 2 
    Range("F:F,H:H,L:L,O:O,S:S,U:U").Select 
    Range("U1").Activate 
    'Selection.NumberFormat = "General" 
    Selection.NumberFormat = "0.00%" 
    Range("A1:B1").Select 
End Sub 
+1

告訴我們你嘗試過什麼至今。 –

回答

0

如果細胞被實際清除恰好包含20個字符(所以LEN(A1)將顯示20),然後選擇單元格要檢查並嘗試:

Sub dural() 
    For Each r In Intersect(Selection, ActiveSheet.UsedRange) 
    If Len(r.Text) = 20 Then 
     r.Clear 
    End If 
    Next r 
End Sub 

編輯#1:

This version will clear cells with a value greater than 1.0E+307: 

Sub dural() 
    For Each r In Intersect(Selection, ActiveSheet.UsedRange) 
     If IsNumeric(r.Value) Then 
      If r.Value > 1E+307 Then 
       r.Clear 
      End If 
     End If 
    Next r 
End Sub 
+0

嗯,我認爲這可行,但顯然不是,腳本在長度不超過20個字符的單元格上觸發,但我剛纔發現的是pund符號背後的真正問題是堆棧溢出。單元格的格式設置爲在單元格被選中時給出0%的值,但實際值爲2.69653970229347E + 308。 我只是想清除那些大聲笑... – xXCableDogXx

+0

我們如何清除其值超過1.E + 308? –

+0

這對我來說很好,除非我不確定如何做到這一點。我越來越好,但我仍然遇到循環和搜索等問題。爲了滿足我的需求,我一直在努力修改其他代碼大約一週,最後我終於在這裏問了一個問題。 – xXCableDogXx

相關問題