軟體:EXCEL
版本:2013
各位版大好~
我寫了一個銷貨單匯入清單的VB
奇怪的是
我從編譯器內案執行一切順利
但是在表單建立按鈕連接VBA程式後
一直出現執行錯誤:型態不符合
重點是我用msgbox回變數型態都是double
第一次遇到這樣
不知道有沒有人知道甚麼
http://imgur.com/a/D1IU7
http://imgur.com/a/D1IU7
感謝
原檔案 https://drive.google.com/file/d/0B5FM7x4Wx7AjcGhvWEJDSGFQT1k/view?usp=sharing
原文如下
Public Sub 匯入清單()
Application.ScreenUpdating = False
Dim r, m, i As Integer
r = Sheets("清單").Cells(66666, 2).End(xlUp).Row
m = WorksheetFunction.CountA(Sheets("銷貨單").Range("B6:B17")) + 1
'填入對應數量
With Sheets("清單")
.Unprotect
.Range(.Cells(r + 1, 1), .Cells(r + m, 1)) = Range("G1").Value - 1
.Range(.Cells(r + 1, 2), .Cells(r + m, 2)) = Range("C1")
.Range(.Cells(r + 1, 3), .Cells(r + m, 3)) = Range("C2")
.Range(.Cells(r + 1, 4), .Cells(r + m, 4)) = Range("C3")
Range(Cells(6, 2), Cells(6 + m - 2, 7)).Copy
.Range(.Cells(r + 1, 5), .Cells(r + m - 3, 10)).PasteSpecial
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
.Cells(r + m, 5) = "折讓"
On Error GoTo XX
.Cells(r + m, 9).Value = -Cells(3, 7)
XX: MsgBox TypeName(.Cells(r + m, 9).Value) & TypeName(-Cells(3, 7))
.Cells(r + m, 11) = Cells(2, 7)
With .Range(.Cells(r + m, 1), .Cells(r + m, 11)).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
'.EnableSelection = xlNoSelection
End With
Application.ScreenUpdating = True
End Sub