我的宏是一个非常简单的替换程序,它识别整个语句的缩短部分并将它们替换为完整语句。出于某种原因,我不断收到 VBA 错误 13:类型不匹配。调试器在我的第一条替换语句中识别出这个错误,然后在接下来的两行中没有识别出错误,当程序运行这些行时甚至会产生预期的结果(我通过注释掉特定行进行了测试)。然后,调试器会在这两行之后的其余语句中发现错误。我不知道发生了什么,非常感谢任何帮助。提前致谢。
//
//
Sub Replacement()
**'Define variables**
Dim firstViolation As String
Dim secondViolation As String
Dim thirdViolation As String
Dim fourthViolation As String
Dim fifthViolation As String
Dim sixthViolation As String
Dim seventhViolation As String
Dim eighthViolation As String
Dim ninthViolation As String
Dim tenthViolation As String
Dim eleventhViolation As String
Dim twelfthViolation As String
Dim thirteenthViolation As String
Dim fourteenthViolation As String
**'Give variables values**
These statements are incredibly long but I am confident there is no error as I simply set the pre-defined variables
**'Code to replace the word violation with the correct descriptions**
Range("G2:G100").Replace What:="IPMC-301.4 Emergency Phone Contact", Replacement:=firstViolation, LookAt:=xlPart
Range("H2:H100").Replace What:="IPMC-302.3 Sidewalks", Replacement:=secondViolation, LookAt:=xlPart
Range("I2:I100").Replace What:="IPMC-302.7 Accessory Structures", Replacement:=thirdViolation, LookAt:=xlPart
Range("J2:J100").Replace What:="IPMC-302.8 Motor vehicles, boats and trailers", Replacement:=fourthViolation, LookAt:=xlPart
Range("K2:K100").Replace What:="IPMC-302.10 Graffiti Removal", Replacement:=fifthViolation, LookAt:=xlPart
Range("L2:L100").Replace What:="IPMC-302.13 Parking of motor vehicles",
Replacement:=sixthViolation, LookAt:=xlPart
Range("M2:M100").Replace What:="IPMC-304.2 Protective Treatment", Replacement:=seventhViolation, LookAt:=xlPart
Range("N2:N100").Replace What:="IPMC-304.3 [F] Premises Identification", Replacement:=eighthViolation, LookAt:=xlPart
Range("O2:O100").Replace What:="IPMC-304.6 Exterior Walls", Replacement:=ninthViolation, LookAt:=xlPart
Range("P2:P100").Replace What:="IPMC-304.7 Roofs and Drainage", Replacement:=tenthViolation, LookAt:=xlPart
Range("Q2:Q100").Replace What:="IPMC-304.3.1 Alley Frontage Identification", Replacement:=eleventhViolation, LookAt:=xlPart
Range("R2:R100").Replace What:="IPMC-307.1 Accumulation of rubbish or garbage", Replacement:=twelfthViolation, LookAt:=xlPart
Range("S2:S100").Replace What:="IPMC-307.2.3 Container Locks", Replacement:=thirteenthViolation, LookAt:=xlPart
Range("T2:T100").Replace What:="IPMC-307.3.4 Additional Capacity Requirements", Replacement:=fourteenthViolation, LookAt:=xlPart