Clever-Excel-Forum

Normale Version: Makro "Suchen und ersetzen"
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo zusammen,

bräuchte ein Makro um in Spalte J:J alle Werte die "NV" anzeigen in eine "0" umzuwandeln.

Hat jemand Rat?
Benutz mal den Makrorecorder.

Grüße
Silcono
Brodiak,

wenn es sich dabei um Formelergebnisse handelt dann ist es keine gute Idee einen Teil der Formeln durch einen Festwert zu ersetzen.
Besser wäre die Verwendung von WENNFEHLER().
Hallo,
Sub NV_Zu_Null()
 On Error Resume Next
 Columns(10).SpecialCells(xlCellTypeFormulas, xlErrors).Value = 0
 On Error GoTo 0
End Sub
Gruß Uwe
Hi,

hier mal etwas universelles für Wennfehler, Istfehler

Code:
Option Explicit
 Sub Set_ifError()
 Dim ErrorMsg As Variant, bol_replaceFormula As Boolean, int_FKind As Integer
 Dim rng_cell As Range, rng_formula As Range, str_F As String
 Dim rngFormula As Range, VK, VE, checkF As Boolean, CheckComp As Boolean
 Dim strFormula1 As String, strFormula2 As String
 On Error Resume Next
 If Cells.SpecialCells(xlCellTypeFormulas, 16) = 0 Then
     If MsgBox("Es sind Fehlermeldungen am Tabellenblatt vorhanden," & Chr(10) & _
     "soll denoch fortgesetzt werden?", vbYesNo) = vbNo Then Exit Sub
 End If
 'Falls in den Versionen ab 2007 eine xls vorliegt
 CheckComp = ActiveWorkbook.CheckCompatibility
 On Error GoTo 0
 With Application
     VK = .Calculation
     VE = .EnableEvents
 End With
 Call speedup(-4135, False, False)
 strFormula1 = "=IFERROR("
 strFormula2 = "=IF(ISERROR("
 '**************************
 'edit what you want
 ErrorMsg = 0 ' was soll als Fehlermeldung erscheinen (ErrorMsg = 0,ErrorMsg = "Error")
 bol_replaceFormula = True ' Nur der markierte Bereich wird ersetzt, bol_replaceFormula = false für ges.Tabellenblatt!
 '*******************************
Set rng_formula = IIf(bol_replaceFormula, Selection, Cells)
 If MsgBox("Sollen nur Formeln mit Fehlerwert ersetzt werden!?" & Chr(10) & _
 "Das würde aber mit hoher Wahrscheinlichkeit eine Inkonsistenz (Inkonsistente Formeln) in Ihrem Tabellenblatt erzeugen.", vbYesNo) = vbYes Then
  int_FKind = 16
  Else
   int_FKind = 23
  End If
 On Error Resume Next
 Set rngFormula = rng_formula.SpecialCells(xlCellTypeFormulas, int_FKind)
 If Err.Number <> 0 Then MsgBox "keine Formeln gefunden": Exit Sub
 If rngFormula.Count > 50000 Then
     If MsgBox("Es wurden " & rngFormula.Count & _
     " Formeln gefunden, sollen wirklich alle Formeln ersetzt werden?", vbYesNo) = vbNo Then Exit Sub
 End If
 On Error GoTo 0
 On Error GoTo errMsg
 If CheckComp Then
     checkF = (MsgBox("Ihre Mappe liegt im Format 97-2003 vor soll Istfehler oder Wennfehler genommen werden" & Chr(10) & _
     "Wennfehler funktioniert nur wenn die Datei ausschließlich in Versionen größer als Excel 2003 verwendet wird" & Chr(10) & _
     "klicken Sie auf JA, wenn WENNFEHLER verwendet werden sollte" & Chr(10) & _
     "klicken Sie auf NEIN wenn ISTFEHLER verwendet werden sollte", vbYesNo) = vbNo)
 End If
 If Val(Application.Version) > 11 And checkF = False Then
     For Each rng_cell In rngFormula
     With rng_cell
         'Merge?
         If Not IsEmpty(.Value) Then
             If InStr(.Formula, strFormula1) = 0 And InStr(.Formula, strFormula2) = 0 Then
                 str_F = strFormula1 & Mid$(.Formula, 2, Len(.Formula) - 1) & "," & ErrorMsg & ")"
                 If .HasArray Then
                     .FormulaArray = str_F
                 Else
                     .Formula = str_F
                 End If
             End If
         End If
       End With
     Next
 Else
     For Each rng_cell In rngFormula
       With rng_cell
         'Merge?
         If Not IsEmpty(.Value) Then
             'Frage nach Wennfehler lasse ich drinnen damit #Name! falls vorhanden NICHT ersetzt wird
             If InStr(.Formula, strFormula1) = 0 And InStr(.Formula, strFormula2) = 0 Then
                 str_F = strFormula2 & Mid$(.Formula, 2, Len(.Formula) - 1) & ")," & ErrorMsg & "," & Mid$(.Formula, 2, Len(.Formula) - 1) & ")"
                 If .HasArray Then
                     .FormulaArray = str_F
                 Else
                     .Formula = str_F
                 End If
             End If
         End If
         End With
       Next
 End If
 Call speedup(VK, VE, True)
 Set rngFormula = Nothing
 Set rng_cell = Nothing
 Set rng_formula = Nothing
 Exit Sub
errMsg:
 Call speedup(VK, VE, True)
 MsgBox Err.Number & " " & Err.Description
 End Sub
Sub speedup(ByVal CalC As Integer, ByVal BolE As Boolean, BolScreenU As Boolean)
   With Application
       .Calculation = CalC
      .EnableEvents = BolE
      .ScreenUpdating = BolScreenU
   End With
 End Sub

Je nach Version, werden wennfehler oder Istfehler eingesetzt.
Die Fehlermeldung kann editiert werden.
Spalte J markieren und Makro laufen lassen.
Danke zusammen,

die Idee mit dem WENNFEHLER ist sehr gut und klappt, also auch die Formel von Kruwer. :18: