Formula To Paste Table In Seperate Worksheet In Excel - excel

I have a table located on Sheet1 called Table2, I just need a way to paste it onto Sheet2 in a certain cell to prepare it for a CSV file. Is there a formula I can use in a cell to display my table in a different sheet?
Table2 dynamically changes from week to week, so I need a formula that'll copy and paste the whole table onto Sheet2.
I've only found how to do a structured table reference, but have not found how to copy and paste the whole table.

In VBA you can use this one line of code in a new module:
Sub CopyTable1ToSheet2A1()
Sheet1.ListObjects("Table1").Range.Copy Destination:=Sheet2.Range("A1")
End Sub

tl;dr; You can insert the table from a connection.
Create your source table if not there already.
Change name if you want, mine is src_table:
Goto "Data -> Get External Data -> Existing Connections"
Goto "Tables" tab and select your table:
In the "Import data" dialog, select how as "Table" and where as wherever you want. In my case I put it in my existing Sheet2 cell A4.
Press Ok
Now if you update the original table in Sheet1, then come back to Sheet2, right click and "Refresh", it'll fetch teh latest data.

Related

VBA - exporting data from cells based on selected row(s)

I have a spreadsheet. I would like to export data from specific cells based on the selected row or rows and import them into a new spreadsheet with a table.
I am not sure how to go about this in excel. I have tired a range but it copies everything. I would like it to be if i select row 5 it take data from B5, E5, F5
I plan to use a userform and macros with a command button to perform this function but i can do all this with no issues
Any help would be greatly appreciated

Changing the data source of pivot table in VBA

My problem goes like this:
I have 2 worksheets in 1 workbook which are the "Source Data" and the "Pivot Sheet". Everytime I generate(I generate data every week and it's in macros), data are added to Source Data sheet but the Pivot Table in the Pivot Sheet remains the same. I think it's quite handy if I will still have to Change Data Source everytime I'll generate the report. I want it to automatically adjust it's data source until the last used cell. How to do it? Columns used as Source are from Column C to W Please help! :(
If you create tables (ctrl + t) for your source data and direct your pivot to read those tables, they should automatically expand as new data is entered. Then it should be as simple as Thisworkbook.Worksheets("Pivot").PivotTables("PivotTable1").PivotCache.Refresh (based on the macro recorder)

Excel: create a LIVE copy of a table on two different sheets of a workbook

I was wondering if it is possible to create a LIVE copy of an excel table on another sheet of the same file.
For a LIVE copy of a table I mean something that is updated every time the original table is updated, that is:
If I change the value of a cell in the original table, the copy is updated
If insert or delete a row/column in the original table, the same row/column is changed in the copy
I am not able to do something like this: if I copy my table, the copy is not updated when I change the original.
If I link one by one the cells of the table with a second table, then when I add or delete a row the second table is unchanged.
Any idea on how can this be solved?
I think you can use Macro VBA for this.
Each time you run codes it will update:
Sub UpdateSheets()
Sheets("Sheet1").Select
Range("A1:D10").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
End Sub
Copy this codes into the VBA module. It can be opened with Alt + F11 and saved. Change the range according to your requirements.

Excel VBA Workbook_open event handler required

I have reference data in columns A and B on Sheet2 of my WorkBook. I have a blank sheet - Sheet1 - which i need to fill from my database.
I want to use Excel VBA to fill Sheet1 based on data in columns A and B in Sheet2.
I use the reference data by.
I populate values in column A in Sheet1 from DB.
I check if the values stored in sheet 1, column A exist in Sheet2 column A,
If so, I populate into sheet 1 column B, the corresponding data i've found in Sheet2 column B.
Open excel, do alt + F11 that will open the IDE.
In the right hand window should see vba project and in brackets the name of the excel book you have open.
At the bottom of the list of sheets is an object called ThisWorkbook, right click it, and select View Code.
At top of should see two combo boxes, right hand one should say General click on it and select Workbook from the list.
This should give you the following
Private Sub Workbook_Open()
End Sub
This is the event that is fired each time the work book is opened. Now you will need to add code to reference the sheets in the workbook.
Here is some methods for how to reference sheets in vba Reference sheets. Next step will be to refer to the cells in the sheets see - > excel ranges as an example.

Insert a Row to a Specific Set of Columns

I'm working on a spreadsheet to act as a master copy for some important information that will be kept track of for a project. On the main sheet I have a table for notes and a table for contacts set up separated by several columns and some VB code to insert new notes or new contacts. However, when I insert a new note I want it to appear at the top of the table and to move all existing notes down a row. Is there any way to add a row to a specific set of columns so that any other data that is kept on cells with the same row, but in a different table, are not moved?
A basic example:
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("A2:D2")
rng.Insert Shift:=xlDown
...assuming that you want to insert 1 row of cells above the cells currently located in A2:D2.
You'll have to code a VBA macro that selects all cells in the notes table as a Range object, and then moves them down one row.
I wouldn't know the exact code, but I'd advise you use the "Record Macro" function and do it by hand: select two cells in an Excel sheet, press the right mouse button and click "Insert". Then it'll ask you if you want to move the rows down. You can see in the newly recorded macro what the code is, and adjust it for your specific purpose. Good luck!

Resources