2012-01-16 14 views
8

मैंने एक फ़ाइल के लिए एक मैक्रो बनाया और सबसे पहले यह ठीक काम कर रहा था, लेकिन आज मैं फ़ाइल खोल रहा हूं और मैक्रो सैकड़ों बार खोल रहा हूं और मुझे हमेशा मिल रहा है निम्न त्रुटि: एक्सेल वीबीए रन-टाइम त्रुटि '13' टाइप मिस्चैचएक्सेल वीबीए रन-टाइम त्रुटि '13' टाइप मिस्चैच

मैंने मैक्रो में कुछ भी नहीं बदला और मुझे नहीं पता कि मुझे त्रुटि क्यों मिल रही है। इसके अलावा मैक्रो को हर बार चलाने के लिए उम्र लगती है जब भी मैं इसे चलाता हूं (मैक्रो को लगभग 9000 पंक्तियां चलाना पड़ता है)।

त्रुटि ** ** के बीच है।

VBA:

Sub k() 

Dim x As Integer, i As Integer, a As Integer 
Dim name As String 
name = InputBox("Please insert the name of the sheet") 
i = 1 
Sheets(name).Cells(4, 58) = Sheets(name).Cells(4, 57) 
x = Sheets(name).Cells(4, 57).Value 
Do While Not IsEmpty(Sheets(name).Cells(i + 4, 57)) 
    a = 0 
    If Sheets(name).Cells(4 + i, 57) <> x Then 
     If Sheets(name).Cells(4 + i, 57) <> 0 Then 
      If Sheets(name).Cells(4 + i, 57) = 3 Then 
       a = x 
       Sheets(name).Cells(4 + i, 58) = Sheets(name).Cells(4 + i, 57) - x 
       x = Cells(4 + i, 57) - x 
      End If 
      **Sheets(name).Cells(4 + i, 58) = Sheets(name).Cells(4 + i, 57) - a** 
      x = Sheets(name).Cells(4 + i, 57) - a 
     Else 
     Cells(4 + i, 58) = "" 
     End If 
    Else 
    Cells(4 + i, 58) = "" 
    End If 

i = i + 1 
Loop 

End Sub 

आपको लगता है कि आप मेरी मदद कर सकते हैं? मैं विंडोज 7 पर एक्सेल 2010 का उपयोग कर रहा हूं। बहुत बहुत धन्यवाद

उत्तर

9

Sheets(name).Cells(4 + i, 57) में एक गैर-संख्यात्मक मान होने पर आपको एक प्रकार का मिलान मिलेगा। इससे पहले कि आप मान लें कि वे संख्याएं हैं और उनसे घटाने का प्रयास करने से पहले आपको फ़ील्ड को सत्यापित करना चाहिए।

इसके अलावा, आपको Option Strict सक्षम करना चाहिए ताकि आपको उन पर प्रकार-निर्भर संचालन करने की कोशिश करने से पहले अपने चर को स्पष्ट रूप से रूपांतरित करने के लिए मजबूर होना पड़े। इससे आपको भविष्य में मुद्दों की पहचान और उन्मूलन करने में भी मदद मिलेगी।       दुर्भाग्यवश Option Strict केवल वीबी.नेट के लिए है। फिर भी, आपको वीबीए में स्पष्ट डेटा प्रकार रूपांतरणों के लिए सर्वोत्तम प्रथाओं को देखना चाहिए।


अद्यतन:

आप अपने कोड की त्वरित सुधार के लिए जाने के लिए हालांकि, कोशिश कर रहे हैं, तो लपेट ** लाइन और एक निम्न स्थिति में यह निम्नलिखित:

If IsNumeric(Sheets(name).Cells(4 + i, 57)) 
    Sheets(name).Cells(4 + i, 58) = Sheets(name).Cells(4 + i, 57) - a 
    x = Sheets(name).Cells(4 + i, 57) - a 
End If 

ध्यान दें कि आपके x मान में अगले पुनरावृत्ति में अपेक्षित मूल्य नहीं हो सकता है।

+0

यह allways संख्यात्मक मान है मैं 0 और 3 – Diogo

+0

के बीच कोड की पहली पंक्ति में त्रुटि आप मुझे दिया गया "संकलित त्रुटि: सिंटैक्स त्रुटि" – Diogo

+0

कोई सिंटैक्स त्रुटि नहीं होना चाहिए। सुनिश्चित करें कि आपने इसे अपने अन्य 'अगर' कथन के बाद सही रखा है और आपके पास सभी कोष्ठक हैं। –

1

डियोगो

जस्टिन आप कुछ बहुत ठीक सुझावों :)

अगर सेल जहां गणना प्रदर्शन कर रहे हैं एक सूत्र से उत्पन्न एक त्रुटि है, तो आप उस त्रुटि मिल जाएगा दे दिया है।

उदाहरण के लिए यदि सेल ए 1 में # DIV/0 है! जब इस कोड

Sheets("Sheet1").Range("A1").Value - 1 

प्रदर्शन कर मैं अपने कोड में कुछ मामूली परिवर्तन किए हैं त्रुटि तो आप "एक्सेल VBA रन-टाइम त्रुटि '13' प्रकार बेमेल" मिल जाएगा। क्या आप कृपया मेरे लिए इसका परीक्षण कर सकते हैं? कोड को लाइन नंबरों के साथ कॉपी करें क्योंकि मैंने जानबूझकर उन्हें वहां रखा है।

Option Explicit 

Sub Sample() 
    Dim ws As Worksheet 
    Dim x As Integer, i As Integer, a As Integer, y As Integer 
    Dim name As String 
    Dim lastRow As Long 
10  On Error GoTo Whoa 

20  Application.ScreenUpdating = False 

30  name = InputBox("Please insert the name of the sheet") 

40  If Len(Trim(name)) = 0 Then Exit Sub 

50  Set ws = Sheets(name) 

60  With ws 
70   If Not IsError(.Range("BE4").Value) Then 
80    x = Val(.Range("BE4").Value) 
90   Else 
100    MsgBox "Please check the value of cell BE4. It seems to have an error" 
110    GoTo LetsContinue 
120   End If 

130   .Range("BF4").Value = x 

140   lastRow = .Range("BE" & Rows.Count).End(xlUp).Row 

150   For i = 5 To lastRow 
160    If IsError(.Range("BE" & i)) Then 
170     MsgBox "Please check the value of cell BE" & i & ". It seems to have an error" 
180     GoTo LetsContinue 
190    End If 

200    a = 0: y = Val(.Range("BE" & i)) 
210    If y <> x Then 
220     If y <> 0 Then 
230      If y = 3 Then 
240       a = x 
250       .Range("BF" & i) = Val(.Range("BE" & i)) - x 

260       x = Val(.Range("BE" & i)) - x 
270      End If 
280      .Range("BF" & i) = Val(.Range("BE" & i)) - a 
290      x = Val(.Range("BE" & i)) - a 
300     Else 
310      .Range("BF" & i).ClearContents 
320     End If 
330    Else 
340     .Range("BF" & i).ClearContents 
350    End If 
360   Next i 
370  End With 

LetsContinue: 
380  Application.ScreenUpdating = True 
390  Exit Sub 
Whoa: 
400  MsgBox "Error Description :" & Err.Description & vbNewLine & _ 
     "Error at line  : " & Erl 
410  Resume LetsContinue 
End Sub 
+0

मुझे त्रुटि मिली "संकलन त्रुटि: वैरिएबल परिभाषित नहीं है" पंक्ति 130 "lastrow =" – Diogo

+0

संशोधित :) कृपया अभी आज़माएं। –

+0

कोई त्रुटि नहीं है, लेकिन जब भी मैं इसे कोशिश करता हूं, तो मेरी एक्सेल शीट ठंड लग रही है :( – Diogo

4

आपकी सभी मदद के लिए धन्यवाद दोस्तों! अंत में मैं इसे एक दोस्त और आप भी पूरी तरह से धन्यवाद करने में सक्षम था! यहां अंतिम कोड है ताकि आप यह भी देख सकें कि हम इसे कैसे हल करते हैं।

फिर से धन्यवाद!

Option Explicit 

Sub k() 

Dim x As Integer, i As Integer, a As Integer 
Dim name As String 
'name = InputBox("Please insert the name of the sheet") 
i = 1 
name = "Reserva" 
Sheets(name).Cells(4, 57) = Sheets(name).Cells(4, 56) 

On Error GoTo fim 
x = Sheets(name).Cells(4, 56).Value 
Application.Calculation = xlCalculationManual 
Do While Not IsEmpty(Sheets(name).Cells(i + 4, 56)) 
    a = 0 
    If Sheets(name).Cells(4 + i, 56) <> x Then 
     If Sheets(name).Cells(4 + i, 56) <> 0 Then 
      If Sheets(name).Cells(4 + i, 56) = 3 Then 
       a = x 
       Sheets(name).Cells(4 + i, 57) = Sheets(name).Cells(4 + i, 56) - x 
       x = Cells(4 + i, 56) - x 
      End If 
      Sheets(name).Cells(4 + i, 57) = Sheets(name).Cells(4 + i, 56) - a 
      x = Sheets(name).Cells(4 + i, 56) - a 
     Else 
     Cells(4 + i, 57) = "" 
     End If 
    Else 
    Cells(4 + i, 57) = "" 
    End If 

i = i + 1 
Loop 
Application.Calculation = xlCalculationAutomatic 
Exit Sub 
fim: 
MsgBox Err.Description 
Application.Calculation = xlCalculationAutomatic 
End Sub 
0

मुझे वही समस्या थी जैसा आपने ऊपर बताया है और मेरा कोड कल पूरे दिन अच्छा प्रदर्शन कर रहा था।

मैंने आज सुबह प्रोग्रामिंग जारी रखा और जब मैंने अपना एप्लिकेशन खोला (मेरी फ़ाइल ऑटो_ ओपन उप के साथ), मुझे रन-टाइम त्रुटि '13' टाइप मिस्चैच मिला, मैं जवाब खोजने के लिए वेब पर गया, मैंने कोशिश की बहुत सी चीजें, संशोधन और एक बिंदु पर मुझे याद आया कि मैंने कहीं "भूत" डेटा के बारे में पढ़ा है जो सेल में रहता है भले ही हम इसे नहीं देखते हैं।

मेरा कोड केवल एक फ़ाइल से डेटा हस्तांतरण करता है जिसे मैंने पहले खोला था और इसे समेट लिया था। मेरा कोड तीसरे शीटटैब पर बंद हो गया (इसलिए यह 2 पिछले शीटटैब के लिए सही हो गया जहां टाइप कोड मिस्चैच संदेश के साथ एक ही कोड रुक गया)। और यह हर बार एक ही शीटटैब पर करता है जब मैं अपना कोड पुनरारंभ करता हूं।

इसलिए मैंने उस सेल का चयन किया जहां यह रुक गया, मैन्युअल रूप से 0,00 दर्ज किया गया (क्योंकि टाइप मिस्चैच एक डीआईएम में घोषित एक सारांश चर से आता है) और उस सेल को सभी बाद की कोशिकाओं में कॉपी किया गया जहां एक ही समस्या आई। यह समस्या हल हो गई। संदेश फिर से नहीं था। मेरे कोड के साथ कुछ भी नहीं बल्कि अतीत से "भूत" या डेटा। ऐसा लगता है जब आप कंट्रोल + एंड का उपयोग करना चाहते हैं और एक्सेल आपको ले जाता है जहां आपके पास डेटा था और इसे हटा दिया गया था। जब आप Excel को सही सेल पर इंगित करते हैं तो यह सुनिश्चित करने के लिए कि आप नियंत्रण + अंत का उपयोग करना चाहते हैं, तब फ़ाइल को "सहेजें" और बंद करना था।

0
Sub HighlightSpecificValue() 

'PURPOSE: Highlight all cells containing a specified values 


Dim fnd As String, FirstFound As String 
Dim FoundCell As Range, rng As Range 
Dim myRange As Range, LastCell As Range 

'What value do you want to find? 
    fnd = InputBox("I want to hightlight cells containing...", "Highlight") 

    'End Macro if Cancel Button is Clicked or no Text is Entered 
     If fnd = vbNullString Then Exit Sub 

Set myRange = ActiveSheet.UsedRange 
Set LastCell = myRange.Cells(myRange.Cells.Count) 

enter code here 
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell) 

'Test to see if anything was found 
    If Not FoundCell Is Nothing Then 
    FirstFound = FoundCell.Address 

    Else 
    GoTo NothingFound 
    End If 

Set rng = FoundCell 

'Loop until cycled through all unique finds 
    Do Until FoundCell Is Nothing 
    'Find next cell with fnd value 
     Set FoundCell = myRange.FindNext(after:=FoundCell) 







    'Add found cell to rng range variable 
     Set rng = Union(rng, FoundCell) 

    'Test to see if cycled through to first found cell 
     If FoundCell.Address = FirstFound Then Exit Do 


    Loop 

'Highlight Found cells yellow 

    rng.Interior.Color = RGB(255, 255, 0) 

    Dim fnd1 As String 
    fnd1 = "Rah" 
    'Condition highlighting 

    Set FoundCell = myRange.FindNext(after:=FoundCell) 



    If FoundCell.Value("rah") Then 
     rng.Interior.Color = RGB(255, 0, 0) 

    ElseIf FoundCell.Value("Nav") Then 

    rng.Interior.Color = RGB(0, 0, 255) 



    End If 





'Report Out Message 
    MsgBox rng.Cells.Count & " cell(s) were found containing: " & fnd 

Exit Sub 

'Error Handler 
NothingFound: 
    MsgBox "No cells containing: " & fnd & " were found in this worksheet" 

End Sub 
0

यह त्रुटि तब होती है जब इनपुट चर प्रकार गलत होता है। आपने शायद Cells(4 + i, 57) में एक सूत्र लिखा है जो =0 के बजाय, सूत्र = "" का उपयोग किया गया है। तो जब यह त्रुटि चल रही है प्रदर्शित होता है। क्योंकि खाली स्ट्रिंग शून्य के बराबर नहीं है।

enter image description here

संबंधित मुद्दे