Expand a table by copying new rows in the end

philoly

New Member
Joined
Sep 26, 2017
Messages
4



I am new in VBA coding and usually I use the recording of macros, but now I need your help because I am stuck.
I have a range C23:K27 with the name (Import_to_Database) in a specific sheet (Copy_to_Database).
I would like to assign a macro to a button in order to copy (special as values) everytime, this range to the bottom of a table with the name ( Black_Database), which is placed in another sheet with the name (Black_Database) Table`s range (A:I) and last step to refresh all the excel workbook.
This is what I tried, but every time, it replaces the same range in the data of the (Black_Database). I don`t know how to write the code in order to add it in the end of the table and expand the table.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Import_to_database()
'
' Import_to_database Macro
'

'
Sheets
("Copy_to_Database").Select
Range
("Table3").Select
Selection
.Copy
Sheets
("Black_Database").Select
ActiveWindow
.SmallScroll Down:=123
Range
("A137").Select
Selection
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application
.CutCopyMode = False
ActiveWorkbook
.RefreshAll
Sheets
("Pivot_Tables").Select
End Sub</code>



Can anybody help me?

Thank you in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
try changing this line Range("A137").Select to Range("A1").End(xlDown).Offset(1, 0).Select
 
Upvote 0

Forum statistics

Threads
1,186,730
Messages
5,959,417
Members
438,422
Latest member
pisuke

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
Top