[英]13 type mismatch error
我正在嘗試在工作表之間發送數據。 當我運行下面的代碼時,我在IncidentReport變量上收到13個不匹配錯誤。 在資料表上,這些范圍是數字范圍,但一個單元格是日期(因此,數字,日期,數字)。 我試圖將IncidentReport聲明為字符串,整數和long,但是我一直收到此錯誤。 正確的變量是什么?
Private Sub Update_Click()
Dim AgentName As String
Dim IncidentReport As Long
Dim MyData As Workbook
'Names variable
Worksheets("sheet1").Select
AgentName = Range("C2")
IncidentReport = Range("D1:F1")
'Opens master workbook
Set MyData = Workbooks.Open("C:\Users\ashley.graham\Field_AgentFolder\Incident Reports\Test folder\Incident reports 2018.xlsx")
'Calls sheet and selects cell
Worksheets("Incident Reports").Select
Worksheets("Incident Reports").Range("a1").Select
'finds next blank row for data entry
RowCount = Worksheets("Incident Reports").Range ("A1").CurrentRegion.Rows.Count
With Worksheets("Incident Reports").Range("A1")
.Offset(RowCount, 0) = IncidentReport
.Offset(RowCount, 1) = AgentName
End With
MyData.Save
End Sub
我認為這是您要嘗試執行的操作:
Private Sub Update_Click()
Dim AgentName As String
Dim IncidentReport As Range
Dim MyData As Workbook
Dim LastRow As Long
With ThisWorkbook.Worksheets("Sheet1")
AgentName = .Range("C2")
Set IncidentReport = .Range("D1:F1")
End With
Set MyData = Workbooks.Open("C:\Users\ashley.graham\Field_AgentFolder\Incident Reports\Test folder\Incident reports 2018.xlsx")
With MyData.Worksheets("Incident Reports")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
.Cells(LastRow, 1) = IncidentReport.Cells(1) 'This will put the first cell value here as don't know what you want.
.Cells(LastRow, 2) = AgentName
End With
MyData.Save
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.