• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Transfer data from one workbook to another workbook Using VBA

Status
Not open for further replies.
Hi, I have two workbooks "Daily_Data" & "Annual_Summary", I need to copy data of multiple columns from "D.Data" wb to "A.Summary" wb, eg: "D.Data wb" Sheet "TALLY SHEET" Range("A1,A3,H4,Q3:Q5,R5,R3,S3:V3") to "Summary WB" Sheet1 & Range("A1:A9"). The next Daily Data Range will be (" A1,A6,H7,Q6:Q8,R8,R6,S6:V6 ") and so on. I tried to write code, but it's not worked as i want. Please guide & help me for the correct code because I'm new in VBA.
Code:
Sub test()
Dim my_range As Range
Dim ws As Worksheet
Dim vFile As Variant
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
Worksheets("TALLY SHEET").Select
Set my_range = Range("A1,A3,H4,Q3:Q5,R5,R3,S3:V3")
Set ws = ThisWorkbook.Sheets("Sheet1")
Do
If Application.WorksheetFunction.CountA(my_range) > 0 Then
my_range.Copy ws.Range("A" & ws.Rows.Count).End(xlUp).Offset(1, 0)
Set my_range = my_range.Offset(1, 0)
Else
Exit Do
End If
Loop

End Sub
 

Attachments

Status
Not open for further replies.
Back
Top