Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 5961|回复: 4

[已解决]运行时错误 ' 13':类型不匹配

[复制链接]
匿名  发表于 2014-10-31 16:16 |阅读模式
本帖最后由 爱疯 于 2014-10-31 16:51 编辑

各位,公司的前辈留下一个表格,运行某项功能时出现 【运行时错误 ' 13':类型不匹配】,我刚接触EXCEL VBA编程,实在是搞不定,还求各位指教,谢谢!代码如下(黄色部分文字为出错的地方):
  1. Function read_lastendtime()
  2.   For i = 9 To Cells(9, 1).CurrentRegion.Rows.Count
  3.     hc = ""
  4.     shipname = trim_(Cells(i, 1), hc)
  5.     If InStr(hc, "V") > 0 Then
  6.     hc = Val(Right(hc, 2))
  7.     line_ = 6
  8.     lastday = ""
  9.     Do While Sheets("外贸结算").Cells(line_, 1) <> shipname And Sheets("外贸结算").Cells(line_, 1) <> "": line_ = line_ + 1: Loop
  10.     Do While Sheets("外贸结算").Cells(line_, 1) = shipname And Sheets("外贸结算").Cells(line_, 1) <> ""
  11.        If lastday < Sheets("外贸结算").Cells(line_, 8) Then lastday = Sheets("外贸结算").Cells(line_, 8): line_lastday = line_
  12.        line_ = line_ + 1
  13.     Loop
  14. <b><font color="#ff8c00">    bugetday = DateValue(Year(Now) & "-" & Cells(1, "R") & "-1 0:00")</font></b>
  15.     If Now() - bugetday > 300 Then
  16.       bugetday = DateValue(Year(Now) + 1 & "-" & Cells(1, "R") & "-1 0:00")
  17.     End If
  18.     If lastday <> "" And Val(Right(Sheets("外贸结算").Cells(line_lastday, 4), 2)) + 1 = Val(Replace(hc, "V", "")) Then Cells(i, "N") = bugetday - DateValue(lastday)
  19.     End If
  20.   Next
  21. End Function
复制代码
最佳答案
2014-10-31 16:21
Cells(1, "R"),看看过个单元格里是什么。
匿名  发表于 2014-10-31 16:18
回复

使用道具

发表于 2014-10-31 16:21 | 显示全部楼层    本楼为最佳答案   
Cells(1, "R"),看看过个单元格里是什么。
回复

使用道具 举报

匿名  发表于 2014-11-3 12:45
hwc2ycy 发表于 2014-10-31 16:21
Cells(1, "R"),看看过个单元格里是什么。

搞清楚了,谢谢!原本R列里的数据不知为何被移到了T,把R改成T就好了
回复

使用道具

发表于 2014-11-3 14:33 | 显示全部楼层
QQ_4C607E 发表于 2014-11-3 12:45
搞清楚了,谢谢!原本R列里的数据不知为何被移到了T,把R改成T就好了

不错,加油。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-19 12:52 , Processed in 0.230818 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表