समस्या:

चर सही ढंग से भंडारण नहीं कर रहा है। कोड चलाने के बाद, मैंने यह पता लगाने के लिए डीबगर का उपयोग किया कि क्या गलत था। चर setRow कोई मान संग्रहीत नहीं कर रहा है। इस प्रकार, एक त्रुटि फेंकना।

कोड:

Public Sub initData(index As Integer)
' ws = COE Monthly Report
' ws2 = FormattedRaw
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("COE Monthly Report")
Dim ws2 As Worksheet
Set ws2 = ThisWorkbook.Sheets("FormattedRaw")
Dim setRow As Integer
Dim countryRow As String
countryRow = ws2.Range("E" & index)
Select Case ws2.Range("A" & index)
Case ws2.Range("A" & index) = "AR"
    Select Case countryRow
        Case countryRow = "Australia"
            setRow = 7
        Case countryRow = "New Zealand"
            setRow = 8
        Case countryRow = "Singapore"
            setRow = 9
        Case Else
            Exit Sub
    End Select
Case ws2.Range("A" & index) = "HW"
    Select Case countryRow
        Case countryRow = "Australia"
            row = 11
        Case countryRow = "New Zealand"
            row = 12
        Case countryRow = "Philippines"
            row = 13
        Case countryRow = "Malaysia"
            row = 14
        Case countryRow = "Singapore"
            row = 15
        Case countryRow = "Thailand"
            row = 16
        Case countryRow = "Vietnam"
            row = 17
        Case countryRow = "Indonesia"
            row = 18
        Case countryRow = "India"
            row = 19
        Case countryRow = "Korea"
            row = 20
        Case countryRow = "Taiwan"
            row = 21
        Case Else
            Exit Sub
    End Select
Case ws2.Range("A" & index) = "PBS"
    Select Case countryRow
        Case countryRow = "Australia"
            row = 23
        Case countryRow = "New Zealand"
            row = 24
        Case countryRow = "Philippines"
            row = 25
        Case countryRow = "Malaysia"
            row = 26
        Case countryRow = "Singapore"
            row = 27
        Case countryRow = "Thailand"
            row = 28
        Case countryRow = "Vietnam"
            row = 29
        Case countryRow = "Indonesia"
            row = 30
        Case countryRow = "Korea"
            row = 31
        Case countryRow = "Taiwan"
            row = 32
        Case Else
            Exit Sub
    End Select
Case ws2.Range("A" & index) = "SWG"
    Select Case countryRow
        Case countryRow = "Australia"
            row = 34
        Case countryRow = "New Zealand"
            row = 35
        Case countryRow = "Philippines"
            row = 36
        Case countryRow = "Malaysia"
            row = 37
        Case countryRow = "Singapore"
            row = 38
        Case countryRow = "Thailand"
            row = 39
        Case countryRow = "Vietnam"
            row = 40
        Case countryRow = "Indonesia"
            row = 41
        Case countryRow = "Indonesia"
            row = 42
        Case countryRow = "Korea"
            row = 43
        Case countryRow = "Taiwan"
            row = 44
        Case Else
            Exit Sub
    End Select
Case ws2.Range("A" & index) = "TSS"
    Select Case countryRow
        Case countryRow = "Singapore"
            row = 46
        Case countryRow = "Malaysia"
            row = 47
        Case countryRow = "Vietnam"
            row = 48
        Case countryRow = "Philippines"
            row = 49
        Case countryRow = "Indonesia"
            row = 50
        Case countryRow = "Thailand"
            row = 51
        Case Else
            Exit Sub
    End Select
End Select
' ~~ If control point type is 'KCFR'
If ws2.Range("L" & index) = "KCFR" Then
    ' ~~ Populate Tested Samples KCFR in COE Monthly Updated
    ws.Range("D" & setRow) = ws.Range("D" & setRow) + 1
    If ws2.Range("AG" & setRow) <> "0" Then
        ' ~~ Populate Defects in KCFR in COE Monthly Updated
        ws.Range("E" & setRow) = ws.Range("E" & setRow) + 1
    End If
' ~~ If control point type is 'KCO'
ElseIf ws2.Range("L" & index) = "KCO" Then
    ' ~~ Populate Tested Samples KCO in COE Monthly Updated
    ws.Range("G" & setRow) = ws.Range("G" & setRow) + 1
    If ws2.Range("AG" & setRow) <> "0" Then
        ' ~~ Populate Defects in KCO in COE Monthly Updated
        ws.Range("H" & setRow) = ws.Range("H" & setRow) + 1
    End If
Else
    Exit Sub
End If
End Sub

ध्यान दें:

मैंने परीक्षण के लिए केवल पहले CASE कथन का उपयोग किया है। तो आप row के रूप में घोषित चर देख सकते हैं लेकिन यह setRow जैसा ही है।

कोई विचार क्यों?

0
Hibari 2 अगस्त 2017, 12:29

2 जवाब

सबसे बढ़िया उत्तर

आपका Select Case स्टेटमेंट सिंटैक्स गलत है, और आप setRow भी टाइप नहीं कर सकते।

आपका एक Select Case कथन कैसा दिखना चाहिए, इसका एक उदाहरण होगा (row से setRow में सुधार सहित):

Select Case countryRow
    Case "Australia"
        setRow = 11
    Case "New Zealand"
        setRow = 12
    Case "Philippines"
        setRow = 13
    Case "Malaysia"
        setRow = 14
    Case "Singapore"
        setRow = 15
    Case "Thailand"
        setRow = 16
    Case "Vietnam"
        setRow = 17
    Case "Indonesia"
        setRow = 18
    Case "India"
        setRow = 19
    Case "Korea"
        setRow = 20
    Case "Taiwan"
        setRow = 21
    Case Else
        Exit Sub
End Select
3
YowE3K 2 अगस्त 2017, 12:43

निम्नलिखित को अपने कोड में रखें:

Debug.Print ws2.Range("A" & index)
Select Case ws2.Range("A" & index)
Stop
Case ws2.Range("A" & index) = "AR"

एक बार जब आप रुक जाते हैं, तो तत्काल विंडो पर एक नज़र डालें कि ws2.Range("A" & index) का मान इसके आधार पर setRow असाइन किया गया है।

1
Vityata 2 अगस्त 2017, 12:36