ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macro for copy-pasting from different workbooks (https://www.excelbanter.com/excel-worksheet-functions/211530-macro-copy-pasting-different-workbooks.html)

Binty

macro for copy-pasting from different workbooks
 
Hi all,

I have to do the following manually everyday to do my daily report.

Copy data from certain columns in a set of data and paste it into a
different workbook, e.g. I want to select only those column with heading 'SR
Num' and 'Date'. However, 'SR Num' will not always be in a particular column
- it can be in 'A', 'B', wherever.

How do I write a macro where it will

- find the columns with headings I want to select,
- copy all the data (rows of data vary day to day) and
- paste it into a different workbook (location for pasting is constant,
however, the file where I'm getting the data from changes everyday)?

Thanks!

Binty





Bernie Deitrick

macro for copy-pasting from different workbooks
 
With the active workbook being the file that you want to get the data from, you could use something
like

Intersect(Cells.Find("SR Num").EntireColumn, ActiveSheet.UsedRange).Copy _
ThisWorkbook.Worksheets("Paste Sheet").Range("A2")

Intersect(Cells.Find("Date").EntireColumn, ActiveSheet.UsedRange).Copy _
ThisWorkbook.Worksheets("Paste Sheet").Range("B2")

HTH,
Bernie
MS Excel MVP


"Binty" wrote in message
...
Hi all,

I have to do the following manually everyday to do my daily report.

Copy data from certain columns in a set of data and paste it into a
different workbook, e.g. I want to select only those column with heading 'SR
Num' and 'Date'. However, 'SR Num' will not always be in a particular column
- it can be in 'A', 'B', wherever.

How do I write a macro where it will

- find the columns with headings I want to select,
- copy all the data (rows of data vary day to day) and
- paste it into a different workbook (location for pasting is constant,
however, the file where I'm getting the data from changes everyday)?

Thanks!

Binty








All times are GMT +1. The time now is 12:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com