pedie
Well-known Member
- Joined
- Apr 28, 2010
- Messages
- 3,875
Hi, I tried to solve this myself but cant think on how to at the moment....first time data in copied in i want it to be pasted to A1, however the next time it brings in the data i want it to keep on pasting it in +1 column...
Thanks in advance for helping!!!
current code. I have hilighted in BOLD Option Explicit
Thanks in advance for helping!!!
current code. I have hilighted in BOLD Option Explicit
Code:
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Sub BringinDesiredData_col()[/FONT]
[FONT=Courier New]Dim thislr, lr As Long[/FONT]
[FONT=Courier New]Dim colHead As Long[/FONT]
[FONT=Courier New]Dim myfound As Range[/FONT]
[FONT=Courier New]Dim wb As Workbook[/FONT]
[FONT=Courier New]Dim tofind As String[/FONT]
[FONT=Courier New]thislr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=Courier New]myfile = "C:\Users\pediez\Desktop\Data.xlsm"[/FONT]
[FONT=Courier New]Set wb = Workbooks.Open(Filename:=myfile)[/FONT]
[FONT=Courier New]ThisWorkbook.Activate[/FONT]
[FONT=Courier New]For Each colHead In Sheet1.Range("A1:A" & thislr)[/FONT]
[FONT=Courier New] If colHead.Value <> "" Then[/FONT]
[FONT=Courier New] tofind = colHead.Text[/FONT]
[FONT=Courier New] wb.Activate[/FONT]
[FONT=Courier New] Sheets("alldata").Activate[/FONT]
[FONT=Courier New] lr = Sheets("alldata").Range("A" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=Courier New] With Sheets("alldata").Rows("1:1")[/FONT]
[FONT=Courier New] Set myfound = .Find(What:=tofind, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole)[/FONT]
[FONT=Courier New] If myfound Is Nothing Then[/FONT]
[FONT=Courier New] MsgBox myfound & "not found"[/FONT]
[FONT=Courier New] Exit Sub[/FONT]
[FONT=Courier New] Else[/FONT]
[FONT=Courier New] [B][U][COLOR=blue]myfound.Resize(lr).copy thisworkbook.Sheets("Sheet1").[/COLOR][/U][/B][/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] End With[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New]Next colHead[/FONT]
[FONT=Courier New]End Sub[/FONT]