How to automatically copy data in multiple spreadsheet

Corried

Board Regular
Joined
Dec 19, 2019
Messages
217
Office Version
  1. 2019
Platform
  1. Windows
  2. Web
In multiple spreadsheets, in ALL cells in "F2" in "workbook 1".
How can I copy ALL cells in "F2" values and paste it VERTICALLY or downward column into a new "workbook 2", "worksheet1" in cell "B2"

See example below


a.PNG

b.PNG


c.PNG


d.PNG


The above worksheets is in "workbook1". All worksheets have data in "F2"
Then
Data is copied and paste into "workbook2" In "sheet1", vertically.

e.PNG
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Assume both workbooks are opened.

Change workbook names as required.
VBA Code:
Sub GetData()
    Dim wb As Workbook, bk As Workbook
    Dim sh As Worksheet, ws As Worksheet
    Dim LstRw As Long, f2 As String
    Set wb = Workbooks("wb2.xlsm")
    Set bk = Workbooks("wb1.xlsx")

    Set ws = wb.Sheets(1)

    For Each sh In bk.Sheets
        f2 = sh.Range("F2").Value

        With ws
            LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
            .Range("A" & LstRw).Value = sh.Name
            .Range("B" & LstRw).Value = f2
        End With
    Next sh

End Sub
 
Upvote 0
I seems like I can't get around this, It looks like I am stuck.
I have followed your tuition. Please set me straight:
Now "workbook2" really name is : "HEATMAP"
and
"workbook1" really name is : "Countries Worksheet PMI"

See below



Sub GetData()
Dim wb As Workbook, bk As Workbook
Dim sh As Worksheet, ws As Worksheet
Dim LstRw As Long, f2 As String
Set wb = Workbooks("HEATMAP .xlsm")
Set bk = Workbooks("Countries Worksheet PMI.xlsx")

Set ws = wb.Sheets(1)

For Each sh In bk.Sheets
f2 = sh.Range("F2").Value

With ws
LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & LstRw).Value = sh.Name
.Range("B" & LstRw).Value = f2
End With
Next sh

End Sub
q.PNG
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

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