Matching List of Name is different Sheets - Copying Adjacent cell values from one to the other

Tron027

New Member
Joined
Nov 4, 2021
Messages
2
Office Version
  1. 2019
Hi,

This is my first time posting here, and I understand that this is a widely asked question, so please bear with me. Unfortunately, I can't seem to get it right for this situation.

I have two worksheets (WS1 and WS2).

WS1 has a list of company names in column B. Each of the 15 company names is repeated under 5 different headings (Opening Balance, Receipts, Payments, Closing Balance & Special Items). Next to each company name is a row of values stretching to column Q representing the amounts per company for their Opening Balance, Receipts, etc.

This report (Report 1) has a specific date allocated to it. The same report is repeated above or below with the same report layout for different periods, linked to a particular "start date".

On WS2, we have Report 2 containing a matching start date, but here each section is split by the company name, and each heading from Report 1 is listed as a line item under the company name.

The first requirement is for Report 2 on WS2 to be matched with Report 1 using the start date linked to each.

After this has been done, the data from Report 1 should be copied per company under each heading and pasted to the matching company name and related line items on WS2.

I have added extracts from the workbook below.

Thanks

WS1
Report 1
01/01/2021
Opening Balance
Google
Apple
Microsoft
IBM
BP
Shell
Naspers
Walmart
Amazon
Toyota
Ford
Volkswagen
Tesla
Tencent
Berkshire Hathaway
Receipts
Google
Apple
Microsoft
IBM
BP
Shell
Naspers
Walmart
Amazon
Toyota
Ford
Volkswagen
Tesla
Tencent
Berkshire Hathaway
Payments
Google
Apple
Microsoft
IBM
BP
Shell
Naspers
Walmart
Amazon
Toyota
Ford
Volkswagen
Tesla
Tencent
Berkshire Hathaway
Closing Balance
Google
Apple
Microsoft
IBM
BP
Shell
Naspers
Walmart
Amazon
Toyota
Ford
Volkswagen
Tesla
Tencent
Berkshire Hathaway
ABC Foods
Special Items
Google
Apple
Microsoft
IBM
BP
Shell
Naspers
Walmart
Amazon
Toyota
Ford
Volkswagen
Tesla
Tencent
Berkshire Hathaway



WS2
Report 2
01/01/2021
Google
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Apple
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Microsoft
Opening Balance
Receipts
Payments
Closing Balance
Special Items
IBM
Opening Balance
Receipts
Payments
Closing Balance
Special Items
BP
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Shell
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Naspers
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Walmart
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Amazon
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Toyota
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Ford
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Volkswagen
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Tesla
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Tencent
Opening Balance
Receipts
Payments
Closing Balance
Special Items
Berkshire Hathaway
Opening Balance
Receipts
Payments
Closing Balance
Special Items
 
Last edited by a moderator:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi and welcome to MrExcel

The same report is repeated above or below with the same report layout for different periods, linked to a particular "start date".
The process must be repeated several times?

The first requirement is for Report 2 on WS2 to be matched with Report 1 using the start date linked to each.
According to your example you have to look for the date "01/01/2021" in sheet ws2, but in which row?

After this has been done, the data from Report 1 should be copied per company under each heading and pasted to the matching company name and related line items on WS2.
I am trying to understand what information to copy and where to paste.

In the forum there is a tool (see my signature), which you can download and install in your excel; the XL2BB tool will allow you to paste data directly from your sheet here. That way you can show an example like this:

WS1
Libro1
ABCDEFGHIJ
1Report 1
201/01/202102/01/2021
3Opening BalanceEXAMPLESOpening BalanceEXAMPLES
4Google1aGoogle1a
5Apple2bApple2b
6Microsoft3cMicrosoft3c
7
8ReceiptsReceipts
9Google6fGoogle6f
10Apple7gApple7g
11Microsoft8hMicrosoft8h
12
13PaymentsPayments
14Google11kGoogle11k
15Apple12lApple12l
16Microsoft13mMicrosoft13m
ws1

WS2
Libro1
ABCDEFGHIJ
1Report 2
201/01/202102/01/202103/01/202104/01/2021
3Google
4Opening Balance1a
5Receipts6f
6Payments11k
7
8Apple
9Opening Balance2b
10Receipts7g
11Payments12l
12
13Microsoft
14Opening Balance3c
15Receipts8h
16Payments13m
ws2
 
Upvote 0
Hi Dante,

Thank you for the quick reply in this regard.

The process must be repeated several times?

Yes, every week a new WS1 Report is compiled, this report shows a consolidated view of forecast data as submitted by various companies for that week. I need the excel workbook to take the information from WS1 on a weekly basis and reshuffle/restructure it to a new layout in the Report on WS2 based on the criteria of the two dates matching up.

According to your example you have to look for the date "01/01/2021" in sheet ws2, but in which row?

That is correct, each week a new Report structure will be created in WS2 with a date, "01/02/2021" in this example. This date will always be found in Column B, in the cell above that weeks report heading - i.e. B4

The corresponding date can be found on WS1 also located in column B.

I have had to adjust my example to only have 5 companies to fit into this posting.

The movement of information would be as follows - Using the first company "Google" as an example.

WS1, C8:Q8 - Copy (Opening Balance: Google)
WS2, C14:Q14 - Paste (Google: Opening Balance)

WS1, C15:Q15 - Copy (Receipts: Google)
WS2, C15:Q15 - Paste (Google: Receipts)

WS1, C22:Q22 - Copy (Payments: Google)
WS2, C16:Q16 - Paste (Google: Payments)

WS2, C17:Q17 - SUM(C14:C16) (Google: Closing Balance)

WS1, C36:Q36 - Copy (Special Item: Google)
WS2, C18:Q18 - Paste (Google: Special Item)

etc.

At the end of the day, the rationality check would be to ensure that the "Consolidated / Group" section at the top of the Report found on WS2 (C7:Q12), which is a SUM formula of all company sections below, matches back to the colour highlighted rows (C7:Q7, C14:Q14, C21:Q21, C28:Q28, C35:Q35) on the Report found in WS1.

Example.xlsm
BCDEFGHIJKLMNOPQ
2WS1
3
401-Feb-21
5ReportWeek 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9Week 10Week 11Week 12Week 13Week 14Week 15
6
7 Opening Balance 3,289(5,521)9,576(553)(6,909)(21,134)(582)15,277(26,310)1,012(8,767)1,60111,054(21,288)14,970
8 Google (2,364)2,6064,6048,4766,486(6,500)7,0322,923(9,651)(9,050)(21)7,4922,856(6,316)(1,357)
9 Apple 7,808(7,774)799,259(1,725)(3,765)(2,175)7,633(5,039)(7,423)5,5112,936(6,932)5,4026,291
10 Microsoft 3,2399,9852,888(909)(7,358)(3,338)4,8837,764(1,832)8,799(4,923)(2,769)9,727(6,776)7,414
11 IBM (8,565)(6,184)8,055(9,955)3,850(1,240)(9,062)4,841(5,003)1,474(9,799)(8,423)2,815(6,995)(456)
12 BP 3,171(4,154)(6,050)(7,424)(8,162)(6,291)(1,260)(7,884)(4,785)7,2124652,3652,588(6,603)3,078
13
14 Receipts 17,30611,46111,77811,8868,95711,0999,85912,0238,21314,48611,7907,3709,22914,33216,195
15 Google 3,7473,1424,2641,3561,7804,6413,0202,9934363,7873,4151,6036203,7443,149
16 Apple 4,0406852,1062,7871,8953,1193,1943,1735522,3192,6941,0322,1303,1102,324
17 Microsoft 3,1222481,6913,0009882,6161,4841,0111,7474,0301,8222,1392,86334,937
18 IBM 4,3604,3072,5804,274209327663,2996431,0626712,0322,2982,8084,065
19 BP 2,0373,0791,1374694,0856911,3951,5474,8353,2883,1885641,3184,6671,720
20
21 Payments (9,825)(6,799)(7,048)(4,778)(6,744)(5,953)(7,037)(5,679)(9,854)(4,397)(6,615)(8,348)(7,395)(6,414)(4,183)
22 Google (4,033)(2,160)(910)(1,669)(709)(2,015)(721)(750)(2,407)(1,282)(1,949)(682)(2,023)(1,313)(648)
23 Apple (1,210)(748)(1,959)(1,430)(1,203)(2,060)(577)(3)(738)(210)(1,078)(2,266)(1,379)(238)(1,779)
24 Microsoft (2,010)(1,170)(2,067)(106)(656)(679)(1,540)(2,226)(2,427)(13)(1,840)(2,389)(1,394)(991)(936)
25 IBM (2,310)(565)(850)(1,226)(1,872)(701)(2,460)(2,177)(1,859)(900)(528)(2,345)(2,489)(1,560)(520)
26 BP (262)(2,156)(1,262)(347)(2,304)(498)(1,739)(523)(2,423)(1,992)(1,220)(666)(110)(2,312)(300)
27
28 Closing Balance 10,770(859)14,3066,555(4,696)(15,988)2,24021,621(27,951)11,101(3,592)62312,888(13,370)26,982
29 Google (2,650)3,5887,9588,1637,557(3,874)9,3315,166(11,622)(6,545)1,4458,4131,453(3,885)1,144
30 Apple 10,638(7,837)22610,616(1,033)(2,706)44210,803(5,225)(5,314)7,1271,702(6,181)8,2746,836
31 Microsoft 4,3519,0632,5121,985(7,026)(1,401)4,8276,549(2,512)12,816(4,941)(3,019)11,196(7,764)11,415
32 IBM (6,515)(2,442)9,785(6,907)2,187(1,909)(10,756)5,963(6,219)1,636(9,656)(8,736)2,624(5,747)3,089
33 BP 4,946(3,231)(6,175)(7,302)(6,381)(6,098)(1,604)(6,860)(2,373)8,5082,4332,2633,796(4,248)4,498
34
35 Special Items 130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000
36 Google 50,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,000
37 Apple 25,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,000
38 Microsoft 10,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,000
39 IBM 30,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,000
40 BP 15,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,000
CA Forecast
Cell Formulas
RangeFormula
B4B4=B43+7
C35:Q35,C21:Q21,C14:Q14,C7:Q7C7=SUM(C8:C12)
C28:Q33C28=SUM(C7,C14,C21)



Example.xlsm
BCDEFGHIJKLMNOPQ
2WS2
3
401-Feb-21
5ReportWeek 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9Week 10Week 11Week 12Week 13Week 14Week 15
6
7Consolidated
8Opening Balance3,289(5,521)9,576(553)(6,909)(21,134)(582)15,277(26,310)1,012(8,767)1,60111,054(21,288)14,970
9Receipts17,30611,46111,77811,8868,95711,0999,85912,0238,21314,48611,7907,3709,22914,33216,195
10Payments(9,825)(6,799)(7,048)(4,778)(6,744)(5,953)(7,037)(5,679)(9,854)(4,397)(6,615)(8,348)(7,395)(6,414)(4,183)
11Closing Balance10,770(859)14,3066,555(4,696)(15,988)2,24021,621(27,951)11,101(3,592)62312,888(13,370)26,982
12Special Items130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000130,000
13Google
14Opening Balance(2,364)2,6064,6048,4766,486(6,500)7,0322,923(9,651)(9,050)(21)7,4922,856(6,316)(1,357)
15Receipts3,7473,1424,2641,3561,7804,6413,0202,9934363,7873,4151,6036203,7443,149
16Payments(4,033)(2,160)(910)(1,669)(709)(2,015)(721)(750)(2,407)(1,282)(1,949)(682)(2,023)(1,313)(648)
17Closing Balance(2,650)3,5887,9588,1637,557(3,874)9,3315,166(11,622)(6,545)1,4458,4131,453(3,885)1,144
18Special Items50,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,00050,000
19Apple
20Opening Balance7,808(7,774)799,259(1,725)(3,765)(2,175)7,633(5,039)(7,423)5,5112,936(6,932)5,4026,291
21Receipts4,0406852,1062,7871,8953,1193,1943,1735522,3192,6941,0322,1303,1102,324
22Payments(1,210)(748)(1,959)(1,430)(1,203)(2,060)(577)(3)(738)(210)(1,078)(2,266)(1,379)(238)(1,779)
23Closing Balance10,638(7,837)22610,616(1,033)(2,706)44210,803(5,225)(5,314)7,1271,702(6,181)8,2746,836
24Special Items25,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,00025,000
25Microsoft
26Opening Balance3,2399,9852,888(909)(7,358)(3,338)4,8837,764(1,832)8,799(4,923)(2,769)9,727(6,776)7,414
27Receipts3,1222481,6913,0009882,6161,4841,0111,7474,0301,8222,1392,86334,937
28Payments(2,010)(1,170)(2,067)(106)(656)(679)(1,540)(2,226)(2,427)(13)(1,840)(2,389)(1,394)(991)(936)
29Closing Balance4,3519,0632,5121,985(7,026)(1,401)4,8276,549(2,512)12,816(4,941)(3,019)11,196(7,764)11,415
30Special Items10,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,00010,000
31IBM
32Opening Balance(8,565)(6,184)8,055(9,955)3,850(1,240)(9,062)4,841(5,003)1,474(9,799)(8,423)2,815(6,995)(456)
33Receipts4,3604,3072,5804,274209327663,2996431,0626712,0322,2982,8084,065
34Payments(2,310)(565)(850)(1,226)(1,872)(701)(2,460)(2,177)(1,859)(900)(528)(2,345)(2,489)(1,560)(520)
35Closing Balance(6,515)(2,442)9,785(6,907)2,187(1,909)(10,756)5,963(6,219)1,636(9,656)(8,736)2,624(5,747)3,089
36Special Items30,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,00030,000
37BP
38Opening Balance3,171(4,154)(6,050)(7,424)(8,162)(6,291)(1,260)(7,884)(4,785)7,2124652,3652,588(6,603)3,078
39Receipts2,0373,0791,1374694,0856911,3951,5474,8353,2883,1885641,3184,6671,720
40Payments(262)(2,156)(1,262)(347)(2,304)(498)(1,739)(523)(2,423)(1,992)(1,220)(666)(110)(2,312)(300)
41Closing Balance4,946(3,231)(6,175)(7,302)(6,381)(6,098)(1,604)(6,860)(2,373)8,5082,4332,2633,796(4,248)4,498
42Special Items15,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,00015,000
LS Forecast
Cell Formulas
RangeFormula
B4B4='CA Forecast'!B4
C8:Q12C8=SUM(C14,C20,C26,C32,C38)
C41:Q41,C35:Q35,C29:Q29,C23:Q23,C17:Q17C17=SUM(C14:C16)
 
Upvote 0
I only have the doubt.
In which row of the sheet "CA Forecast" you have the data "Report", in your example, it appears in the row 5. If it is not row 5, then change the 5 to the row number in the next line of the macro:
VBA Code:
lc = sh1.Cells(5, Columns.Count).End(1).Column

Try this:
VBA Code:
Sub consolidate_report()
  Dim sh1 As Worksheet
  Dim a As Variant, b As Variant, c As Variant
  Dim hd As Variant, hds As Variant
  Dim i As Long, j As Long, k As Long, lr As Long, lc As Long, m As Long, n As Long
  Dim f As Range
  Dim dic As Object
  Dim itm As String
  
  Set dic = CreateObject("Scripting.Dictionary")
  Set sh1 = Sheets("CA Forecast")
  lr = sh1.Range("B" & Rows.Count).End(3).Row
  lc = sh1.Cells(5, Columns.Count).End(1).Column
  
  hds = Array("Opening Balance", "Receipts", "Payments", "Closing Balance", "Special Items")
  ReDim c(0 To UBound(hds) + 1)
  a = sh1.Range("B1", sh1.Cells(lr, lc)).Value
  ReDim b(1 To UBound(a, 1) * 2, 1 To UBound(a, 2))
  
  i = 1
  For Each hd In hds
    Set f = sh1.Range("B:B").Find(hd, , xlValues, xlPart, , , False)
    If Not f Is Nothing Then
      c(n) = f.Row
      n = n + 1
      b(i, 1) = hd
      For j = 2 To UBound(a, 2)
        b(i, j) = a(f.Row, j)
      Next
      i = i + 1
    End If
  Next
  c(UBound(c)) = lr + 1
  
  For k = 0 To UBound(c) - 1
    For m = c(k) + 1 To c(k + 1) - 1
      itm = Trim(a(m, 1))
      If itm <> "" Then
        If Not dic.exists(itm) Then
          b(i, 1) = itm
          i = i + 1
          dic(itm) = i
          n = dic(itm)
          i = i + UBound(hds) + 1
        Else
          n = dic(itm) + 1
          dic(itm) = n
        End If
        b(n, 1) = hds(k)
        For j = 2 To UBound(a, 2)
          b(n, j) = a(m, j)
        Next
      End If
    Next
  Next
  
  With Sheets("LS Forecast")
    .Range("B8", .Cells(Rows.Count, Columns.Count)).ClearContents
    .Range("B8").Resize(UBound(b, 1), UBound(b, 2)).Value = b
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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