Type mismatch error?!?

adamenel

New Member
Joined
Mar 9, 2023
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi guys,

I'm desperately trying to resolve type mismatch error but no results. Any tips?
This button is supposed to copy all data from actual worksheet/table (SourceTable) to the end of summary table (DestinationTable) in other sheet.

Private Sub CommandButton1_Click()

Dim SourceTable, DestinationTable As ListObject


Set SourceTable = ActiveSheet.ListObjects("ZN")
Set DestinationTable = Sheets("Zbirni").ListObjects("ZBIRNI")

SourceTable.DataBodyRange.Copy Destination:=DestinationTable.DataBodyRange.Offset(DestinationTable.DataBodyRange.Rows.Count).Resize(1, 1).PasteSpecial(SourceTable).xlPasteValues

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi @adamenel, Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Please, try the following code:

VBA Code:
Private Sub CommandButton1_Click()
  Dim SourceTable, dt As ListObject

  Set SourceTable = ActiveSheet.ListObjects("ZN")
  Set dt = Sheets("Zbirni").ListObjects("ZBIRNI")
  
  SourceTable.DataBodyRange.Copy dt.DataBodyRange.Offset(dt.DataBodyRange.Rows.Count).Resize(1, 1)
End Sub

Or this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim SourceTable, dt As ListObject
  Dim nrow As Long

  Set SourceTable = ActiveSheet.ListObjects("ZN")
  Set dt= Sheets("Zbirni").ListObjects("ZBIRNI")
  dt.ListRows.Add AlwaysInsert:=True
  nrow = dt.DataBodyRange.Rows.Count
  SourceTable.DataBodyRange.Copy dt.ListRows(nrow).Range
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Last edited:
Upvote 0
Hi @adamenel, Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Please, try the following code:

VBA Code:
Private Sub CommandButton1_Click()
  Dim SourceTable, dt As ListObject

  Set SourceTable = ActiveSheet.ListObjects("ZN")
  Set dt = Sheets("Zbirni").ListObjects("ZBIRNI")
 
  SourceTable.DataBodyRange.Copy dt.DataBodyRange.Offset(dt.DataBodyRange.Rows.Count).Resize(1, 1)
End Sub

Or this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim SourceTable, dt As ListObject
  Dim nrow As Long

  Set SourceTable = ActiveSheet.ListObjects("ZN")
  Set dt= Sheets("Zbirni").ListObjects("ZBIRNI")
  dt.ListRows.Add AlwaysInsert:=True
  nrow = dt.DataBodyRange.Rows.Count
  SourceTable.DataBodyRange.Copy dt.ListRows(nrow).Range
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
Hi Dante,

Thanks for the warm welcome and your prompt response. The second option works fine. Somehow after execution of code (copy/paste process) a range of cells is left selected in source sheet. Any idea how to remove that selection? Another question is how to paste content in destination table shifted by 1 column to the right?

Regards,
Adam
 
Upvote 0
Somehow after execution of code (copy/paste process) a range of cells is left selected in source sheet. Any idea how to remove that selection? Another question is how to paste content in destination table shifted by 1 column to the right?

Try this:
VBA Code:
Private Sub CommandButton1_Click()
  Dim SourceTable As ListObject, dt As ListObject
  Dim nrow As Long

  Set SourceTable = ActiveSheet.ListObjects("ZN")
  Set dt = Sheets("Zbirni").ListObjects("ZBIRNI")
  dt.ListRows.Add AlwaysInsert:=True
  nrow = dt.DataBodyRange.Rows.Count
  SourceTable.DataBodyRange.Copy dt.DataBodyRange.Cells(nrow, 2)
  SourceTable.DataBodyRange.Cells(1).Select
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top