weixin_38225865 2021-03-08 14:28 采纳率: 100%
浏览 268
已采纳

求大神相助,一小段vba调试不通

这段程序要实现的是:
把“电话回访记录_临时”表中的“退单”“发门锁单”所在行的一些信息,
写入“电话回访记录_所有”表中。
一直调试不通,报错:运行时错误‘9’,下标越界

Sub TuiDaMenSuoDan()
    Dim dateFaShengRiQi As Date
    Dim strYongHuDiZhi As String
    Dim strYongHuDianHua As String
    Dim strZhuangTai As String
    Dim strYuanGong As String
    Dim strFanYingRen As String
    Dim i As Integer
    Dim strGongZuoBiaoMing As String
    Dim wb As Workbook
    Dim intMuBiaoBiaoZuiHouYiHang As Integer
    Dim intGongZuoBiaoChangDu As Integer
'**********************************************
    Workbooks.Open Filename:="d:\Documents\电话回访记录_20210305\电话回访记录_所有.xlsx"
    strGongZuoBiaoMing = InputBox("请输入工作表名:")
    intGongZuoBiaoChangDu = Worksheets(strGongZuoBiaoMing).Range("A65536").End(xlUp).Row
    For i = 1 To intGongZuoBiaoChangDu
        If Trim(Sheets(strGongZuoBiaoMing).Cells(i, "C")) = "退单" Then
            dateFaShengRiQi = Sheets(strGongZuoBiaoMing).Cells(i, "D")
            strYongHuDiZhi = Sheets(strGongZuoBiaoMing).Cells(i, "I")
            strYongHuDianHua = Sheets(strGongZuoBiaoMing).Cells(i, "J")
            strZhuangTai = Sheets(strGongZuoBiaoMing).Cells(i, "C")
            If Sheets(strGongZuoBiaoMing).Cells(i, "N") = "" Then
                strYuanGong = ""
            Else
                strYuanGong = Sheets(strGongZuoBiaoMing).Cells(i, "N")
            End If
            strFanYingRen = Sheets(strGongZuoBiaoMing).Cells(i, "H")
            MsgBox (strFanYingRen)
'***********************************************
            intMuBiaoBiaoZuiHouYiHang = Worksheets(Trim("2021-03")).Range("A65536").End(xlUp).Row
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "A") = dateFaShengRiQi
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "B") = strYongHuDiZhi
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "C") = strYongHuDianHua
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "D") = strZhuangTai
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "E") = strYuanGong
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "H") = strFanYingRen
        End If
    Next i
'**********************************************
    For i = 1 To intGongZuoBiaoChangDu
        If Trim(Sheets(strGongZuoBiaoMing).Cells(i, "L")) = "发门锁单" Then
            dateFaShengRiQi = Sheets(strGongZuoBiaoMing).Cells(i, "D")
            strYongHuDiZhi = Sheets(strGongZuoBiaoMing).Cells(i, "I")
            strYongHuDianHua = Sheets(strGongZuoBiaoMing).Cells(i, "J")
            strZhuangTai = Sheets(strGongZuoBiaoMing).Cells(i, "L")
            If Sheets(strGongZuoBiaoMing).Cells(i, "N") = "" Then
                strYuanGong = ""
            Else
                strYuanGong = Sheets(strGongZuoBiaoMing).Cells(i, "N")
            End If
            strFanYingRen = Sheets(strGongZuoBiaoMing).Cells(i, "H")
            MsgBox (strFanYingRen)
'***********************************************
            intMuBiaoBiaoZuiHouYiHang = Worksheets(Trim("2021-03")).Range("A65536").End(xlUp).Row
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "A") = dateFaShengRiQi
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "B") = strYongHuDiZhi
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "C") = strYongHuDianHua
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "D") = strZhuangTai
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "E") = strYuanGong
            Sheets("2021-03").Cells(intMuBiaoBiaoZuiHouYiHang + 1, "H") = strFanYingRen
        End If
    Next i
End Sub
  • 写回答

5条回答 默认 最新

  • Go 旅城通票 2021-03-08 16:32
    关注

    你确认你的Excel文件路径正确?

    还有工作表名称也是对的?

    如果这2个有一个出错都会提示越界的错误。

     

        strGongZuoBiaoMing = Trim(InputBox("请输入工作表名:")) 
        '增加下面的语句看下表名称都有什么,是不是全数字由于Excel版本不一样导致名称变了
           For Each s In ActiveWorkbook.Sheets
             MsgBox "|" & s.Name & "|"
          Next

    不知道你数据格式怎么样的,按照你的代码瞎编的数据测试没有问题。

    o(╥﹏╥)o话说我安装了2016测试做表明名称全数字也是没问题。。。

     

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)