Vba 我的宏显示运行时错误1004。请查收

Vba 我的宏显示运行时错误1004。请查收,vba,excel,Vba,Excel,我在运行时遇到了1004错误。错误在这一行: 如果IsNumeric(wkbCurr.Sheets(CTRYname).Range(column&x).Value)=True,则 我要做的是选择工作表(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 currSA

我在运行时遇到了1004错误。错误在这一行:

如果IsNumeric(wkbCurr.Sheets(CTRYname).Range(column&x).Value)=True,则

我要做的是选择工作表(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        
Public Sub-MoM\u Check()
作为整数的Dim inti
作为整数的Dim intj
将k变为整数
作为整数的Dim mnth
以双倍价格出售
以双倍价格出售
2%为双倍
Dim CTRYname作为字符串
作为整数的Dim x
将列设置为字符串
'查找本月extarct和上月extarct中24个普通月的销售额之间的差异百分比
对于n=1到13
Application.wWorkbook=4
设置wkbTemp=工作簿。添加
CTRYname=ThisWorkbook.Sheets(“国家/地区查找”).Range(“A1”).Offset(n,0)。值
'打开临时工作簿以执行所有计算
'首先,将当前月份的摘录复制到第一张工作表
“我们现在使用usedrange复制从wkbout到wkbtemp的工作表
wkbCurr.Sheets(CTRYname).激活
wkbCurr.Sheets(CTRYname).UsedRange.Copy
wkbTemp.板材(“板材1”).范围(“A1”).特殊粘贴
wkbprev.Sheets(CTRYname)。激活
wkbprev.Sheets(CTRYname).UsedRange.Copy
wkbTemp.板材(“板材2”).范围(“A1”).特殊粘贴
'打开上个月的主提取文件,如查找选项卡中所示。此数据粘贴在临时工作簿的第2页上。
这张表帮助我们比较本月摘录中的国家频道与上月摘录中的国家频道。
因此,这张表也遵循同样的流程,同样地,我们从上个月的摘录中获得了国家频道,并将它们粘贴到“sheet3”上
'Prevcnt包含上月摘录中的国家/地区频道数
k=1
对于mnth=0到22
currSALE=wkbTemp.Sheets(“Sheet1”).范围(“AB10”).偏移量(0,mnth).值
prevSALE=wkbTemp.板材(“板材2”).范围(“AC10”).偏移量(0,mnth).值
如果prevSALE=0且currSALE为0,则
diffpercent=1
如果prevSALE=0,currSALE=0,则
diffpercent=0
其他:diffpercent=(currSALE-prevSALE)/prevSALE
如果结束
如果diffpercent>0.01或diffpercent<-0.01,则
设置wkbRaw=Workbooks.Open(strOutputQCPath&“Errorlog.xlsx”)
wkbRaw.表(“表1”)。激活
wkbRaw.Sheets(“Sheet1”)。范围(“A1”)。偏移量(i,1+n)。值=CTRYname&“不正确”
退出
其他的
设置wkbRaw=Workbooks.Open(strOutputQCPath&“Errorlog.xlsx”)
wkbRaw.表(“表1”)。激活
wkbRaw.Sheets(“Sheet1”)。范围(“A1”)。偏移量(i,1+n)。值=CTRYname&“正确”
k=k+1
wkbRaw.SaveAs文件名:=strOutputQCPath&“Errorlog.xlsx”
wkbRaw,关门
如果结束
下一个mnth
对于x=1到15
如果x=1或x=2或x=3或x=4或x=6或x=9或x=10或x=11或x=13,则
转到名称
其他的
如果IsNumeric(wkbCurr.Sheets(CTRYname).Range(column&x).Value)=True,则
如果wkbCurr.Sheets(CTRYname).Range(column&x).Value>9.99,则
wkbCurr.Sheets(CTRYname).Range(列和x).Value=“>999%”
ElseIf wkbCurr.Sheets(CTRYname).范围(列和x).值<-9.99

wkbCurr.Sheets(CTRYname).Range(column&x).Value=“您没有给字符串“column”一个值,这就是为什么在该行出现错误1004的原因。

因此如果我要选择第1列,它将不能作为Range(column1)工作?
column
需要指定一个特定的值。它以空字符串开始
”“
-这意味着对于x=1,您的
.Range(列&x)
将以
.Range(“1”)
结束,这是无效的。”。如果要查看B列,则需要有一行,如:
column=“B”
,然后查看
。范围(column&x)
将是
。范围(“B1”)