Extracting data from another workbook

BradleyN1

New Member
Joined
May 5, 2017
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi,

I've spent some time trying to figure this out but I've given up, so, I'm seeking some help please!

I have two workbooks, workbook 1 works as an overiew page and workbook 2 has all the data I want to extract to it.
I have an example below.

Example.xlsx
ABCDEFGHIJ
1WORKBOOK 1WORKBOOK 2
2
3REVIEW 1REVIEW 2IDReviewStatusCompleted by
4IDStatusCompleted byStatusCompleted by1Review 1CompleteName 1
51CompleteName 12Review 1Not startedName 2
623Review 2Needs actionName 3
73Needs actionName 3
8
9I want this workbook to pull across the status of reviews if the ID matches, and the review aligns to the header. Example results are populated.
10
11
12
13
14
15
Sheet1


Thanks
smile.gif
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Check below code:

Assuming, data in your sheet is as below:

WB1.xlsx
ABCDE
1REVIEW 1REVIEW 2
2IDStatusCompleted byStatusCompleted by
31CompleteName 1
42Not StartedName 2
53Needs actionName 3
Sheet1



VBA Code:
Option Explicit

Sub copyData()
    Dim wb1 As Workbook, targetRow As Integer
    Dim rowno As Integer, totalRows As Integer
    
    Set wb1 = Workbooks("WB1.xlsx")
    totalRows = wb1.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For rowno = 3 To totalRows
        targetRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
        wb1.Sheets("Sheet1").Range("A" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("A" & targetRow)
        If wb1.Sheets("Sheet1").Range("B" & rowno) <> "" Then
            ThisWorkbook.Sheets("Sheet1").Range("B" & targetRow) = "Review 1"
            wb1.Sheets("Sheet1").Range("B" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("C" & targetRow)
            wb1.Sheets("Sheet1").Range("C" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("D" & targetRow)
        Else
            ThisWorkbook.Sheets("Sheet1").Range("B" & targetRow) = "Review 2"
            wb1.Sheets("Sheet1").Range("D" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("C" & targetRow)
            wb1.Sheets("Sheet1").Range("E" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("D" & targetRow)
        End If
    Next

End Sub
 
Upvote 0
Thanks for your very prompt response :)
I will check this out! Can I just clarify, is this only possible via VBA, there's not a formula for this?
 
Upvote 0
Hi,

Check below code:

Assuming, data in your sheet is as below:

WB1.xlsx
ABCDE
1REVIEW 1REVIEW 2
2IDStatusCompleted byStatusCompleted by
31CompleteName 1
42Not StartedName 2
53Needs actionName 3
Sheet1



VBA Code:
Option Explicit

Sub copyData()
    Dim wb1 As Workbook, targetRow As Integer
    Dim rowno As Integer, totalRows As Integer
   
    Set wb1 = Workbooks("WB1.xlsx")
    totalRows = wb1.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
   
    For rowno = 3 To totalRows
        targetRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
        wb1.Sheets("Sheet1").Range("A" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("A" & targetRow)
        If wb1.Sheets("Sheet1").Range("B" & rowno) <> "" Then
            ThisWorkbook.Sheets("Sheet1").Range("B" & targetRow) = "Review 1"
            wb1.Sheets("Sheet1").Range("B" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("C" & targetRow)
            wb1.Sheets("Sheet1").Range("C" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("D" & targetRow)
        Else
            ThisWorkbook.Sheets("Sheet1").Range("B" & targetRow) = "Review 2"
            wb1.Sheets("Sheet1").Range("D" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("C" & targetRow)
            wb1.Sheets("Sheet1").Range("E" & rowno).Copy ThisWorkbook.Sheets("Sheet1").Range("D" & targetRow)
        End If
    Next

End Sub
Sorry, forgot to actually reply to your message!
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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