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

您没有给字符串“column”一个值,这就是为什么您在该行收到错误 1004。

于 2012-09-17T10:46:35.433 回答