2017-06-15 1 views
0

ich Fehler für meinen VBA-Makro in dieser Zeile bekommen:VBA: 'definierte oder Objekt definierten Fehler' bei If und Funktion Dann

If Sheets("Check Foil").Cells(y, 15) = Sheets("Data").Cells(x, 19) And Sheets("Check Foil").Cells(y, 24).Value <> "0" Then 

Dies ist mein Code:

x = 1 
    y = 16 
    Do 
     If Sheets("Check Foil").Cells(y, 15) = Sheets("Data").Cells(x, 19) And Sheets("Check Foil").Cells(y, 24).Value <> "0" Then 
      Sheets("Data").Cells(x, 21).Copy 
      Sheets("Check Foil").Cells(y, 21).PasteSpecial xlPasteAll 
      Sheets("Check Foil").Cells(y, 22) = "Anode Foil not scan completely" 
      With Sheets("Check Foil").Range(Sheets("Check Foil").Cells(y, 21), Sheets("Check Foil").Cells(y, 24)).Borders 
        .LineStyle = xlContinuous 
        .Weight = xlThin 
        .ColorIndex = xlAutomatic 
      End With 
      y = y + 1 
     Else 
      Sheets("Check Foil").Cells(y, 22) = "Foil Info Not Found" 
     End If 
     x = x + 1 
    Loop Until Sheets("Check Foil").Cells(y, 15) = "" 

    Sheets("Check Foil").Range("M16:X1016").VerticalAlignment = xlCenter 
    Sheets("Check Foil").Range("M:M").HorizontalAlignment = xlCenter 
    Sheets("Check Foil").Range("N16:O1016").HorizontalAlignment = xlLeft 
    Sheets("Check Foil").Range("P16:V1016").HorizontalAlignment = xlRight 

    y = 16 
    Do 
     If Sheets("Check Foil").Cells(y, 24) <= Application.WorksheetFunction.Sum(Sheets("Check Foil").Cells(y, 23) - (Sheets("Check Foil").Cells(y, 23) * 0.1)) And Sheets("Check Foil").Cells(y, 24).Value <> "0" Then 
      Sheets("Check Foil").Range(Sheets("Check Foil").Cells(y, 13), Sheets("Check Foil").Cells(y, 24)).Interior.ColorIndex = 6 
     End If 
     y = y + 1 
    Loop Until Sheets("Check Foil").Cells(y, 14) = "" 

    Worksheets("Check Foil").Activate 
    ActiveSheet.Range("A1").Select 

    MsgBox "Program Complete Run" 

End Sub 
+0

Diese Linie gleichen Fehler werden können. Wenn Sheets ("Check Foil") Zellen (y, 24) <= Application.WorksheetFunction .Sum (Sheets ("Check Foil"). Zellen (y, 23) - (Sheets ("Check Foil"). Zellen (y, 23) * 0,1)) und Sheets ("Check Foil"). Zellen (y, 24) .Wert <> "0" Dann – Falhuddin

+0

Was sind die Werte von 'x',' y', 'Sheets (" Check Foil "). Zellen (y, 15)', 'Sheets (" Daten "). Zellen (x, 19) 'und' Sheets ("Check Foil"). Zellen (y, 24) 'wenn der Code abstürzt? – YowE3K

Antwort

0

Sie eigentliches Problem , Sie vermissen ".value" im ersten Vergleich. so:

If (Sheets("Check Foil").Cells(y, 15).Value = Sheets("Data").Cells(x, 19).Value) And (Sheets("Check Foil").Cells(y, 24).Value <> "0") Then 
      Sheets("Data").Cells(x, 21).Copy 

Aber dieses verbessert werden könnte:

Dim wb As Workbook 
Dim ws_foil As Worksheet 
Dim ws_data As Worksheet 

Set wb = ThisWorkbook 
Set ws_foil = wb.Sheets("Check Foil") 
Set ws_foil = wb.Sheets("Data") 

foil_data = ws_foil.Cells(y, 15).Value 
data_data = ws_data.Cells(x, 19).Value 

foil_data1 = ws_foil.Cells(y, 24).Value 

If ((foil_data = data_data) And (foil_data1 <> 0)) Then 
    ws_data.Cells(x, 21).Copy 
End If 
+0

'.Value' ist (indirekt) die Standardeigenschaft eines' Range' Objektes. Während ich persönlich es vorziehe, es immer zu benutzen, ** funktioniert ** ohne es. – YowE3K

Verwandte Themen