我目前收到"Error 13: Type Mismatch "以下代碼的錯誤,我似乎無法找到問題的來源
我已經添加了 Option Explicit 代碼來嘗試和提供幫助,但在程式執行時它仍然沒有突出顯示任何內容。
Option Explicit
Public mainWB As Workbook
Public mainWS As Worksheet
Public newWS As Worksheet
Sub Main()
'Creating New Variables
Dim TranstactDate As String, AmountExcl As Single
Dim mainR As Long, mainC As Long, newR As Long, newC As Long
Dim randNumber As Long
Dim accHolder As String
newR = 2 'start of writing Row
Set mainWB = Workbooks("arrears-formatter.xlsx") 'Setting mainWB
Set mainWS = mainWB.Worksheets("arrears-formatter") ' set mainWS to the working Worksheet
mainWB.Activate 'Shows that were working in the mainWB workbook
randNumber = Int((99999 - 10000 1) * Rnd 10000)
TranstactDate = mainWS.Cells(1, 2)
For mainR = 9 To 1000
If mainWS.Cells(mainR, 1) = "" Then GoTo exitthis:
accHolder = Left(mainWS.Cells(mainR, 1), 3)
AmountExcl = mainWS.Cells(mainR, 3)
While Left(mainWS.Cells(mainR, 1), 3) = accHolder
Set newWS = mainWB.Worksheets(accHolder "-" randNumber)
newWS.Range("A2:A1000").NumberFormat = "@"
'Determining new sheet values
newWS.Cells(newR, 1) = TranstactDate
newWS.Cells(newR, 1).NumberFormat = "dd/mm/yyy"
newWS.Cells(newR, 2) = mainWS.Cells(mainR, 1)
newWS.Cells(newR, 3) = "AR"
newWS.Cells(newR, 4) = "Interest"
newWS.Cells(newR, 5) = "0"
newWS.Cells(newR, 6) = "7"
newWS.Cells(newR, 7) = "Interest"
newWS.Cells(newR, 8) = ""
newWS.Cells(newR, 9) = AmountExcl
newWS.Cells(newR, 10) = ""
newWS.Cells(newR, 11) = ""
newWS.Cells(newR, 12) = "0"
newWS.Cells(newR, 13) = AmountExcl
newWS.Cells(newR, 14) = "1"
newWS.Cells(newR, 15) = AmountExcl
newWS.Cells(newR, 16) = AmountExcl
newWS.Cells(newR, 17) = "0"
newWS.Cells(newR, 18) = "0"
newWS.Cells(newR, 19) = ""
newWS.Cells(newR, 20) = "0"
newWS.Cells(newR, 21) = "0"
newWS.Cells(newR, 22) = "0"
newWS.Cells(newR, 23) = ""
newWS.Cells(newR, 24) = ""
newWS.Cells(newR, 25) = "0"
newWS.Cells(newR, 26) = "0"
newWS.Cells(newR, 27) = ""
newWS.Cells(newR, 28) = "0"
newWS.Cells(newR, 29) = "0"
newWS.Cells(newR, 30) = "0"
newWS.Cells(newR, 31) = "2750>050"
newWS.Cells(newR, 32) = "0"
newWS.Cells(newR, 33) = "0"
newR = newR 1
Wend
exitthis:
Next mainR
newWS.Cells(1, 1) = "Trans Date"
newWS.Cells(1, 2) = "Account"
newWS.Cells(1, 3) = "Module"
newWS.Cells(1, 4) = "Trans Code"
newWS.Cells(1, 5) = "Post Date"
newWS.Cells(1, 6) = "Reference"
newWS.Cells(1, 7) = "Description"
newWS.Cells(1, 8) = "Order Number"
newWS.Cells(1, 9) = "Amount Excl"
newWS.Cells(1, 10) = "Tax Type"
newWS.Cells(1, 11) = "Tax Account"
newWS.Cells(1, 12) = "Is Debit"
newWS.Cells(1, 13) = "Amount Incl"
newWS.Cells(1, 14) = "Exchange Rate"
newWS.Cells(1, 15) = "Foreign Amount Excl"
newWS.Cells(1, 16) = "Foreign Amount Incl"
newWS.Cells(1, 17) = "Discount Percent"
newWS.Cells(1, 18) = "Discount Amount Excl"
newWS.Cells(1, 19) = "Discount Tax Type"
newWS.Cells(1, 20) = "Discount Amount Incl"
newWS.Cells(1, 21) = "Foreign Discount Amount Excl"
newWS.Cells(1, 22) = "Foreign Discount Amount Incl"
newWS.Cells(1, 23) = "Project Code"
newWS.Cells(1, 24) = "Rep Code"
newWS.Cells(1, 25) = "Split Group"
newWS.Cells(1, 26) = "Split GL Account"
newWS.Cells(1, 27) = "Split Description"
newWS.Cells(1, 28) = "Split Amount"
newWS.Cells(1, 29) = "Foreign Split Amount"
newWS.Cells(1, 30) = "Split Project Code"
newWS.Cells(1, 31) = "GL Contra Code"
newWS.Cells(1, 32) = "Split Tax Type"
newWS.Cells(1, 33) = "Split Tax Account"
With newWS.Sort
.SortFields.Add Key:=Range("C2"), Order:=xlAscending
.SetRange Range("A2:G1000")
.Header = xlNo
.Apply
End With
End Sub
如果您能看到此錯誤的來源,請提供幫助,它僅用于重新格式化 Excel 作業表
uj5u.com熱心網友回復:
您正在嘗試使用亂數創建新作業表:
Set newWS = mainWB.Worksheets(accHolder "-" randNumber)
但是,這不會創建作業表。您需要先創建作業表,然后重命名作業表。
Set newWS = mainwb.Sheets.Add
newWS.Name = accholder & "-" & randNumber
此外,您試圖使用“ ”符號連接變數和字串,您需要使用與號“&”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/324383.html
