Adding data from Array to end of existing data in another workbook

daopsmatt

New Member
Joined
Jan 31, 2017
Messages
4
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hello all,

I have banging my head against the wall for a couple of days on this one. I know it must be so simple I am overlooking something.

Goal: Copy data from one workbook into an Array. Then paste that data into another workbook after the last row of data already there.
Here is what I already have. My challenge, I think is, figuring out the "next available row in spreadsheet 2 and cycling through the Array to paste the data.

Challenge, both workbooks, will have unknown number of rows to start with because they are system generate reports with data that changes.

Any help would be great, like I said it probably is so simple I am just overthinking it.

Thank you.

VBA Code:
Sub BarioArray()

' Copy column and paste at end of another columns data
'
    Dim arrBario() As Variant
    Dim myCount As Integer
    Dim lastRow As Long
    Dim wbBario As Workbook: Set wbBario = Application.Workbooks("Bario.xls")
    Dim wsBario As Worksheet
    Set wsBario = wbBario.Sheets("report")
    
' Fill Array
    arrBario = Range("A1").CurrentRegion
    
' empty array
With Worksheets("Sheet1")
    For myCount = LBound(arrBario) To UBound(arrBario)
        .Cells((0 + myCount), 1).Value = arrBario(myCount, 1)
    Next myCount
End With

Range("A1").Select
lastRow = wsBario.Cells(Rows.Count, 1).End(xlUp).Row
nextRow = Range(("A") & (lastRow + 1)).Select

With wsBario
    For myCount = LBound(arrBario) To UBound(arrBario)
      .Cells((nextRow + myCount), 1).Value = arrBario(myCount, 4)
    Next myCount
End With

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I didn't quite understand which column you want to copy, or where you want to paste it.
But if you only want to pass column A of sheet1 to report sheet, then:

VBA Code:
Sub copydata()
  Dim a As Variant
  a = Sheets("Sheet1").Range("A1", Sheets("Sheet1").Range("A" & Rows.Count).End(3)).Value2
  Workbooks("Bario.xlsx").Sheets("report").Range("A" & Rows.Count).End(3)(2).Resize(UBound(a)).Value = a
End Sub
 
Upvote 0
Thank you DanteAmor

Sorry, I should have added that information, you are correct.

I am creating an array with the information on the Bario sheet. Currently, I am trying to the information in the array spot #4 and paste it at the end of the data in Column A same sheet, just so I can figure that out.

Ultimately, I want to take the data on the array from Bario and move it to Air List Workbook, I am copying 6 columns of data, and want to up it at the end of the existing data in the Air List workbook same columns.
 
Upvote 0
Sorry, I still don't understand.
You want to copy data from a source sheet to another target sheet, if so, you could explain like this:

Sheet("NameA").range("X") origin.
Sheet("NameB").range("Y") destination.

Replace "nameA", "NameB", "X", "Y" with the real names.
 
Upvote 0
Sorry if I am not explaining it correctly, I am very novice at VBA and self-taught so I know that doesn't help.

I was doing a Copy Paste from sheet to the other but was trying to speed up the process by using an array and using less code that if someone had to clean it up later they could.

Thank you so much for your help. I really appreciate it.
 
Upvote 0
Okay, using a array will help speed up the process.
But if you explain what range you want to copy from which sheet and where you want to paste it and in which cell, I help you simplify the code.

You should not even explain it with VBA code, only explain with simple words source sheet, source cells, target sheet, target cell.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top