TextJoin VBA macro from one blank cell to another

AECJohn

New Member
Joined
Jun 23, 2022
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Hi,

I am trying to create a macro that does a text join for the data between two blank cells (see example table below). I would like it to do a text join for the invoice numbers for each company, in the company total column. Is this possible?

NameEuroUSDRateInvoiceRequested ByVendor ContactDue DatePaid DateStatusTab
Company A€ 7,236.92$ 7,633.3299-123456
20/05/2022​
01/11/2022Exported01.11.22
Company A€ 5,262.19$ 5,525.30
1.050000095​
99-123457
21/05/2022​
01/11/2022Exported01.11.22
Company A€ 1,974.73$ 2,108.02
1.067497835​
99-123458
22/05/2022​
01/11/2022Exported01.11.22
Company A€ 7,236.92$ 7,633.3299-123459
30/05/2022​
01/11/2022Exported01.11.22
Company A€ 7,236.92$ 7,633.3299-123468
29/06/2022​
01/11/2022Exported01.11.22
Company A€ 5,262.19$ 5,525.30
1.050000095​
99-123469
30/06/2022​
01/11/2022Exported01.11.22
Company A€ 1,974.73$ 2,108.02
1.067497835​
99-123470
01/07/2022​
01/11/2022Exported01.11.22
Company A Total€ 36,184.60$ 38,166.60
Company B€ 427.50$ 456.36
1.067508772​
87-654321
29/05/2022​
01/11/2022Exported01.11.22
Company B€ 427.50$ 456.36
1.067508772​
87-654322
08/06/2022​
01/11/2022Exported01.11.22
Company B€ 427.50$ 456.36
1.067508772​
87-654325
08/07/2022​
01/11/2022Exported01.11.22
Company B Total€ 1,282.50$ 1,369.08
Company C€ 7,212.70$ 7,573.33167-85643
24/05/2022​
01/11/2022Exported01.11.22
Company C€ 8,351.45$ 8,769.02
1.049999701​
167-85644
25/05/2022​
01/11/2022Exported01.11.22
Company C€ 7,212.70$ 7,573.33167-85645
03/06/2022​
01/11/2022Exported01.11.22
Company C€ 8,351.45$ 8,769.02
1.049999701​
167-85646
04/06/2022​
01/11/2022Exported01.11.22
Company C€ 7,212.70$ 7,573.33167-85647
13/06/2022​
01/11/2022Exported01.11.22
Company C€ 8,351.45$ 8,769.02
1.049999701​
167-85648
14/06/2022​
01/11/2022Exported01.11.22
Company C€ 7,212.70$ 7,573.33167-85649
23/06/2022​
01/11/2022Exported01.11.22
Company C€ 8,351.45$ 8,769.02
1.049999701​
167-85650
24/06/2022​
01/11/2022Exported01.11.22
Company C€ 7,212.70$ 7,573.33167-85651
03/07/2022​
01/11/2022Exported01.11.22
Company C€ 8,351.45$ 8,769.02
1.049999701​
167-85652
04/07/2022​
01/11/2022Exported01.11.22
Company C Total€ 77,820.75$ 81,711.75
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
For example:
VBA Code:
Sub AllByCompany()
Dim I As Long, AllInv As String
'
Sheets("Sheet1").Select
For I = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    If Right(Cells(I, 1), 6) = " Total" Then
        Cells(I, "E").Value = Mid(AllInv, 3)
    Else
        AllInv = AllInv & ", " & Cells(I, "E")
    End If
Next I
Range("E1:E" & I).WrapText = False
End Sub
 
Upvote 0
Possibly this?
For the moment I have assumed at least two rows for each company. If it is possible there is only row for a company a small adjustment would be needed.
VBA Code:
Sub ListInvoices()
  Dim rA As Range
 
  For Each rA In Range("E2", Range("E" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
    rA.Cells(rA.Count + 1).Value = Join(Application.Transpose(rA.Value), ", ")
  Next rA
End Sub

Here is part of my sheet after the code.

AECJohn.xlsm
AE
1NameInvoice
2Company A99-123456
3Company A99-123457
4Company A99-123458
5Company A99-123459
6Company A99-123468
7Company A99-123469
8Company A99-123470
9Company A Total99-123456, 99-123457, 99-123458, 99-123459, 99-123468, 99-123469, 99-123470
10Company B87-654321
11Company B87-654322
12Company B87-654325
13Company B Total87-654321, 87-654322, 87-654325
14Company C167-85643
15Company C167-85644
16Company C167-85645
17Company C167-85646
18Company C167-85647
19Company C167-85648
20Company C167-85649
21Company C167-85650
22Company C167-85651
23Company C167-85652
24Company C Total167-85643, 167-85644, 167-85645, 167-85646, 167-85647, 167-85648, 167-85649, 167-85650, 167-85651, 167-85652
Sheet1 (2)
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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