VBA and pasting into a table

Rush01

New Member
Joined
Mar 11, 2019
Messages
3
Hi all

I've done my utmost to find solutions elsewhere but despite my best efforts I'm still lost.
I'm trying to set up a bed board for a hospital ward, I've managed the basics, setting up a table to record who is in what bed, but I need now to be able to archive the patients when they leave in a separate table for lookup later. I'm using buttons for each "bed" to set the range (Bed) before calling the below Sub and then clearing the row.
I'm coming unstuck when pasting, as I want to paste the set range into the last row of Table1, but each time I paste it goes beneath the table instead! The code I have at present is -



Sub CopyFormulas()
Dim sht2 As Worksheet


Set sht2 = Sheets("Sheet2")


Bed.Copy
sht2.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False


response = MsgBox("patient has left the ward")


End Sub

I've tried various ListObjects solutions, but to be honest I'm not sure I understand them!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi NoSparks

I did review this page before, but couldn't get my head round how to get it to fit with what I need. I think I'm missing a value for the "Set oNewRow" line. I've altered the Selection & ListObjects to reflect the table. But am getting "Object Required" when running the code, and the oNewRow= nothing in debug.
I'm 100% sure I'm missing something really basic, but can't for the life of me figure what.
 
Upvote 0
try this
Code:
Dim sht2 As Worksheet
Dim oLo As ListObject
Dim oNewRow As ListRow

Set sht2 = Sheets("Sheet2")
Set oLo = sht2.ListObjects(1)   'the first table on this sheet
Set oNewRow = oLo.ListRows.Add  'adds new row to bottom of table

Range("Bed").Copy
oNewRow.Range.PasteSpecial
 
Upvote 0
Oops. Bed is a range you've already set, not a named range, so it's
Bed.Copy
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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