I have several columns with headers in one excel workbook, I want to copy some of these columns into another workbook.
Let’s say I have my origin workbook:
Ident|Name|Code|Part|Desc|U|Total
These are the headers of the columns with some data below them.
And I want to copy only the data in the columns Ident, Code and Part in another workbook that has the same headers but in a different order with the exception that one header has a different name:
Code|Ident|Piece
It is blank and Piece corresponds to Part. So I want a code that takes the data from the origin workbook and copy it to the destination workbook. Also if possible I’d like that you can choose the original workbook from a file as I have different excel files to choose from.
Thank you for your answers. I have never used VBA and I’m trying to learn.
I have the following code that lets you choose the data you want manually but I want something similar that does it automatically after recognizing the headers.
Sub ImportDatafromotherworksheet()Dim wkbCrntWorkBook As WorkbookDim wkbSourceBook As WorkbookDim rngSourceRange As RangeDim rngDestination As RangeSet wkbCrntWorkBook = ActiveWorkbookWith Application.FileDialog(msoFileDialogOpen) .Filters.Clear .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa" .AllowMultiSelect = False .Show If .SelectedItems.Count > 0 Then Workbooks.Open .SelectedItems(1) Set wkbSourceBook = ActiveWorkbook Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8) wkbCrntWorkBook.Activate Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8) rngSourceRange.Copy rngDestination rngDestination.CurrentRegion.EntireColumn.AutoFit wkbSourceBook.Close False End IfEnd WithEnd Sub