0

実行中に 1004 エラーが発生します。エラーは次の行にあります。

If IsNumeric(wkbCurr.Sheets(CTRYname).Range(column & x).Value) = True Then

私がしたいのは、シート(CTRYNAME)を選択してから、列5、7、9などを検索し、コードで行われたように数字をフォーマットすることです。

Public Sub MoM_Check()
Dim inti As Integer
Dim intj As Integer
Dim k As Integer
Dim mnth As Integer
Dim currSALE As Double
Dim prevSALE As Double
Dim diffpercent As Double
Dim CTRYname As String
Dim x As Integer
Dim column As String

    'Find Difference percentage between sales of 24 common months in present month's extarct and previous month's extract

  For n = 1 To 13
  Application.SheetsInNewWorkbook = 4
Set wkbTemp = Workbooks.Add

CTRYname = ThisWorkbook.Sheets("Country lookup").Range("A1").Offset(n, 0).Value

'Open a temporary workbook to do all the Calculations
'First the current month's extract is copied to the first sheet

'We now copy sheets for range from wkbout to wkbtemp using usedrange
wkbCurr.Sheets(CTRYname).Activate
wkbCurr.Sheets(CTRYname).UsedRange.Copy
wkbTemp.Sheets("Sheet1").Range("A1").PasteSpecial
wkbprev.Sheets(CTRYname).Activate
wkbprev.Sheets(CTRYname).UsedRange.Copy

 wkbTemp.Sheets("Sheet2").Range("A1").PasteSpecial

'open the Previous month's Main Extract file as given in the lookup tab. This data is pasted on sheet2 of temporary workbook.
'This sheet helps us to compare the country channels in current month's extract with the previous Month's Extract.
'So the same process is followed for this sheet and similarly we get the country channels from the previous month's extract and paste them on 'sheet3

'Prevcnt contains the number of country channels in the previous month's extract
          k = 1

  For mnth = 0 To 22

  currSALE = wkbTemp.Sheets("Sheet1").Range("AB10").Offset(0, mnth).Value
  prevSALE = wkbTemp.Sheets("Sheet2").Range("AC10").Offset(0, mnth).Value
   If prevSALE = 0 And currSALE <> 0 Then
   diffpercent = 1
   ElseIf prevSALE = 0 And currSALE = 0 Then
   diffpercent = 0
   Else: diffpercent = (currSALE - prevSALE) / prevSALE
   End If

   If diffpercent > 0.01 Or diffpercent < -0.01 Then
   Set wkbRaw = Workbooks.Open(strOutputQCPath & "Errorlog.xlsx")
     wkbRaw.Sheets("Sheet1").Activate

   wkbRaw.Sheets("Sheet1").Range("A1").Offset(i, 1 + n).Value = CTRYname & " Incorrect"

    Exit For
   Else
    Set wkbRaw = Workbooks.Open(strOutputQCPath & "Errorlog.xlsx")
    wkbRaw.Sheets("Sheet1").Activate
    wkbRaw.Sheets("Sheet1").Range("A1").Offset(i, 1 + n).Value = CTRYname & " Correct"

     k = k + 1
     wkbRaw.SaveAs Filename:=strOutputQCPath & "Errorlog.xlsx"
     wkbRaw.Close

      End If
         Next mnth

  For x = 1 To 15

    If x = 1 Or x = 2 Or x = 3 Or x = 4 Or x = 6 Or x = 9 Or x = 10 Or x = 11 Or x = 13      Then
    GoTo Name
    Else
    If IsNumeric(wkbCurr.Sheets(CTRYname).Range(column & x).Value) = True Then
        If wkbCurr.Sheets(CTRYname).Range(column & x).Value > 9.99 Then
            wkbCurr.Sheets(CTRYname).Range(column & x).Value = ">999%"
        ElseIf wkbCurr.Sheets(CTRYname).Range(column & x).Value < -9.99 Then
            wkbCurr.Sheets(CTRYname).Range(column & x).Value = "<-999%"
        End If
    End If
    End If
Name:
  Next x

     wkbTemp.Close savechanges:=False
    Set wkbTemp = Nothing

  Next n 
End Sub        

助けてください!

4

1 に答える 1

1

文字列「列」に値を指定していないため、その行でエラー 1004 が発生します。

于 2012-09-17T10:46:35.433 に答える