Reputation: 25
Type Mismatch error while copy data from excel to another excel
I am getting Type Mismatch error .. please help thanks
Private Sub CommandButton1_Click()
Dim dataRange As String
Dim myData As Workbook
Worksheets("Sheet1").Select
dataRange = Range("A1:T1")
Set myData = Workbook.Open("C:\Users\mahather\Desktop\Report\Test.xlsx")
Worksheets("Sheet1").Select
Worksheets("Sheet1").Range("A3:T3").Select
RowCount = Worksheets("Sheet1").Range("A3:T3").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A3:T3")
RowCount = dataRange
End With
myData.Save
End Sub
Upvotes: 0
Views: 64
Reputation:
This code will run and I've tried to guess your purpose. You will be left with an open workbook.
Private Sub CommandButton1_Click()
Dim dataRange As variant, myData As Workbook
dataRange = Worksheets("Sheet1").range("A1:T1").value
Set myData = Workbooks.Open("C:\Users\mahather\Desktop\Report\Test.xlsx")
with mydata.Worksheets("Sheet1")
with .Range("A3:T3").CurrentRegion
.offset(.rows.count, 0).resize(1, .columns.count) = dataRange
end with
.parent.save
'.parent.close savechanges:=true
end with
End Sub
Upvotes: 0
Reputation: 96753
The problem is with:
RowCount = dataRange
because RowCount
is a Long or Integer and DataRange
is a multi-cell Range
Upvotes: 1