Search for a column based on the column header and then past data from it to another column in anoth

M

minkokiss

Hey guys I am trying to develop a macro that will search for specific
column header names in an opened workbook, if the header is found I
will get the data from the column data under the header and paste in
into another column in another Workbook without specifying formating.
Any help for that would be great. Thank you

minkokiss
 
J

JLGWhiz

I did not test this, so you should before using in the original workbook.

Sub FindCopyPaste()
myHdr = Cells(1, Columns.Count).End(xlToLeft).Column
myRng = Range(Cells(1, 1), Cells(1, myHdr))
With myRng
Set c = .Find("HeaderName", After:=myHdr, Lookin:=xlValues)
If Not c Is Nothing Then
xRng = c.Address
Range(xRng).Offset(1, 0).EntireColumn.Copy
Workbooks("DifferentOne").Sheets("Whatever").Range("$A$1")
End If
End With
End Sub
 
J

JLGWhiz

This is actually one line in code:

Range(xRng).Offset(1, 0).EntireColumn.Copy
Workbooks("DifferentOne").Sheets("Whatever").Range("$A$1")

There is a space between Copy and Workbooks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top