Copying data from one workbook to another - with extras - excel

I am looking for a solution to create the code to copy data from Workbook 1 Sheet 1 to another workbook that will be closed. I also want to make sure that the data being pasted is in the next empty row, so in essence:
Active workbook 1, sheet 1 copy any data from row 2 to the last row
Paste in to inactive workbook 2 in the first row that is empty
Hope this make sense!

Record this task with Excel macro Recorder and you have 90% of your code. To make sure you got the last empty row place the Cursor in Cell A1, press Button END and then Cursor down.
This site is to help If you need some coder service please use other Portals like here

Related

Excel - Deleting a row does not automatically insert a blank row

As seen in the photos, I have a particular sheet in my workbook that refuses to add a blank row to the bottom of the worksheet after a row is deleted. Why is this happening, and how can I fix it?
Here is a screenshot of a the bottom of a typical sheet in my workbook before I delete a row
After I delete a row on the good sheet, another row is automatically inserted on the bottom
Now here is the bottom of the problem sheet before I delete a row
After I delete the row on the problem sheet, a new row is not being automatically added to the sheet
Rows cannot be added or destroyed. An Excel sheet has a static number of rows and columns at all times. This limit depends on the version of the workbook housing the worksheet. Rows an columns can be hidden but they are never truly gone.
Complete details about the limitations of Excel can be found here:
https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

VBA- Delete entire row in sheet 1

I have been using the following to delete a row.
Rows([2]).EntireRow.Delete
But this was when my workbook had only one sheet. A command button has been added in sheet2 which calls the macro present in sheet1.
How should I modify my above code so that the VBA deletes the second row of sheet1 ?
You only need to specify which which sheet the row is in, in addition to specifying the row as you already do. I.e.
Worksheets("Sheet1").Rows(2).EntireRow.Delete
Should do what you wish. If you have called the worksheet something different than "Sheet1", change what is inside the quotation marks. Strictly speaking you don't need to specify that it is the entire row you want to delete, as you've already said it is the row you are dealing with with Rows(2), but it shouldn't do any harm in there either.
If you additionally want to do the deletion from a different workbook (or just make sure that the deletion takes place in the correct workbook), you can also specify the workbook-name:
Workbooks("Workbookname.xlsm").Worksheets("Sheet1").Rows(2).EntireRow.Delete
If your button is in any other sheet and you wants to delete a row from another sheet, you simply have to activate that sheet. For example, you are trying to delete row from Sheet1 then you can activate the sheet by this one-liner.
Sheets(0).Activate

Automate data transfer between workbooks in Excel

I admit to not being very technical and my limit up to now has been using paste links to connect data between sheets. I now have a requirement I cannot figure out.
I have 2 workbooks I wish to automate sharing data between.
Workbook 1 contains multiple rows of data manually entered.
I need a button against each row so when it is pressed data from certain cells on that row in Workbook 1 are transferred to cells within a worksheet in workbook 2
I would be very grateful for any guidance on how to achieve this.
Many thanks!
Though you can deploy VBA to achieve this, but the same is also possible with simple formula like.
=[1.xlsx]Sheet1!$A$1
Lets say you have two workbooks 1.xlsx and 2.xlsx and you want sheet1/column A1 value from 1.xlsx to be auto populated in sheet1/column A1 in 2.xlsx, you can simply link it with a formula like =[1.xlsx]Sheet1!$A$1 in second workbook 2.xlsx.
So as soon as some entry is done in first cell, second cell is auto populated
However if you are looking only for vba solution do write back

Copy excel (2007) sheet to new workbook without formulas referencing original workbook

I have a workbook with two sheets. The first is full of data and calculations, the second is mostly cells with references to the first sheet. The second sheet also concatenates strings, and references to cells in the sheet, to form SQL commands used elsewhere.
There is also a second workbook (soon to be more). It has a sheet identical to the first sheet of the other workbook, except with different data. The problem I'm having is that the new workbook needs a sheet similar to the second of the original workbook (sorry if this is sounding confusing). I would like to simply duplicate the sheet and its formulas, which I tried using the 'move or copy...' option. Unfortunately, the formulas in the cells reference the first sheet from the old workbook, like this: =[foobar.xlsx]data!A1. Way too much data to remove them by hand. I can't just redo the formulas because I had to remove a lot of specific lines from the second sheet, so dragging the formula would not match up correctly. I'm currently trying to hack this together with REPLACE but if anyone can offer help it would be greatly appreciated.
CLARIFICATION:
When I copy the sheet, a formula will appear as =[foobar.xlsx]data!A1. I want it to just be data!A1.
Thanks :)
I hope this answers your problem, but I am a little unclear on your need!!!
Highlight all cells in the worksheet.
Perform a replace to replace = with say '=
This stops the formulas "being formulas"
Copy the sheet.
Perform another replace on the new sheet to replace '= with =
This converts back to formulas, referring to cells in your new workbook.

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