VBA to create new tables below existing table depending on variables

pscofe

New Member
Joined
Jan 24, 2020
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hi, so I have the table below which will change daily:

local_acc_noclosing_balancecurrencyclosing_balance_eurstmt_dateFEED_TYPEbalanceDayCountTeamComments
Paul
-3,830,439.00​
JPY
-32,700.77​
15/04/2020 00:00:00STM
43,597,701.00​
1​
AExpense
Jack
-2,248,520.60​
IDR
-132.17​
15/04/2020 00:00:00STM
-2,248,520.60​
3​
BExpense
Chris
-1,713,448.18​
USD
-1,571,250.05​
15/04/2020 00:00:00STM
10,330,502.38​
2​
AExpense
John
-1,163,793.13​
USD
-1,067,210.57​
15/04/2020 00:00:00STM
251,530.81​
1​
AExpense
Steven
-919,493.09​
USD
-843,184.86​
15/04/2020 00:00:00STM
337,087.79​
2​
BExpense
Marianne
-6,568.79​
EUR
-6,568.79​
15/04/2020 00:00:00STM
13,018,289.65​
2​
BExpense
Mary
-69.80​
RON
-14.44​
15/04/2020 00:00:00STM
-69.80​
5​
AWrite off
Jane
-36.92​
EUR
-36.92​
15/04/2020 00:00:00STM
0.00​
31​
AWrite off
Julia
-4.00​
ISK
-0.03​
15/04/2020 00:00:00STM
0.00​
34​
CWrite off
Tony
-1.00​
JPY
-0.01​
15/04/2020 00:00:00STM
0.00​
5​
CWrite off
Harry
-0.54​
CHF
-0.51​
15/04/2020 00:00:00STM
-0.54​
29​
AWrite off
Sebastian
-0.36​
NOK
-0.03​
15/04/2020 00:00:00STM
0.05​
1​
CWrite off
Nicola
-0.31​
SEK
-0.03​
15/04/2020 00:00:00STM
-0.31​
5​
AWrite off

I need a VBA code to put into a macro:

I want to keep that table where it is but two lines below, to have the headings and all the Team A together. Then a table two lines below that one, with headings and Team B. Etc.

local_acc_noclosing_balancecurrencyclosing_balance_eurstmt_dateFEED_TYPEbalanceDayCountTeamComments
Paul
-3,830,439.00​
JPY
-32,700.77​
15/04/2020 00:00:00STM
43,597,701.00​
1​
AExpense
Chris
-1,713,448.18​
USD
-1,571,250.05​
15/04/2020 00:00:00STM
10,330,502.38​
2​
AExpense
John
-1,163,793.13​
USD
-1,067,210.57​
15/04/2020 00:00:00STM
251,530.81​
1​
AExpense


local_acc_noclosing_balancecurrencyclosing_balance_eurstmt_dateFEED_TYPEbalanceDayCountTeamComments
Jack
-2,248,520.60​
IDR
-132.17​
15/04/2020 00:00:00STM
-2,248,520.60​
3​
BExpense
Steven
-919,493.09​
USD
-843,184.86​
15/04/2020 00:00:00STM
337,087.79​
2​
BExpense
Marianne
-6,568.79​
EUR
-6,568.79​
15/04/2020 00:00:00STM
13,018,289.65​
2​
BExpense

Also, anyway I can change the date to get rid of the 00:00:00?

Really appreciate the help!
Thanks,
P
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try:
VBA Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim LastRow As Long, team As Range, rngList As Object, key As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set rngList = CreateObject("Scripting.Dictionary")
    For Each team In Range("I2:I" & LastRow)
        If Not rngList.Exists(team.Value) Then
            rngList.Add team.Value, Nothing
        End If
    Next team
    For Each key In rngList
        Cells(1, 1).CurrentRegion.AutoFilter 9, key
        ActiveSheet.AutoFilter.Range.Copy Cells(Rows.Count, "A").End(xlUp).Offset(3)
    Next key
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
wow! Yes that's worked! Unbelievable

If i want to amend the Team to something different (so instead of A, B and C) where do I do that in the code? They're more likely to be something like OPS, Middle Office etc
is there a quick way to format the date as well?
Thank you so much, amazing
 
Upvote 0
the code itself works on anything I put in column I and separates it, just tried it. That's incredible! haha

If can get the date sorted then i have the perfect report! Thanks
 
Upvote 0
You are very welcome. :)
If you amend the Team, the code will work as is. Select the date column and format it as "Date". Unfortunately, you won't see a change in the existing dates. You will have to re-enter them to see the change. Any new dates in that column will appear without the time.
 
Upvote 0
You are very welcome. :)
If you amend the Team, the code will work as is. Select the date column and format it as "Date". Unfortunately, you won't see a change in the existing dates. You will have to re-enter them to see the change. Any new dates in that column will appear without the time.

cool, that code is fantastic! thanks again
 
Upvote 0
Hello,

You kindly sent me below which was looking at Column I and collating different teams into their own tables....if you remember?!?! I've had to add Column J into the table but it's strange that it goes days without working and then randomly works. I suspect it's how i've created the table itself (from another macro) but is there anything you can think of why it's not working all the time and if easy to fix? Really appreciate any help if poss.

Sub team()

Application.ScreenUpdating = False
Dim LastRow As Long, team As Range, rngList As Object, key As Variant
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set rngList = CreateObject("Scripting.Dictionary")
For Each team In Range("I2:I" & LastRow)
If Not rngList.Exists(team.Value) Then
rngList.Add team.Value, Nothing
End If
Next team
For Each key In rngList
Cells(1, 1).CurrentRegion.AutoFilter 9, key
ActiveSheet.AutoFilter.Range.Copy Cells(Rows.Count, "A").End(xlUp).Offset(3)
Next key
Range("A1").AutoFilter
Application.ScreenUpdating = True
End Sub

Initial table

FundCustody BalCurrencyEUR EquivDateFeed typeBluebay BalDayCountTeamComments
John-8,704,731.42GBP-9,740,791.1919/05/2020 00:00:00Stmt Ccy Message2,961,898.784AChased
Terry-2,061,400.19NZD-1,149,281.2119/05/2020 00:00:00Stmt Ccy Message36,621.574BFx
Antonia-1,181,792.59GBP-1,322,452.6219/05/2020 00:00:00Stmt Ccy Message625,207.414BFx
marianne-1,018,429.26MXN-39,472.3719/05/2020 00:00:00Stmt Ccy Message117,962.624BFx
Sebastian-83,905.52EUR-83,905.5219/05/2020 00:00:00Stmt Ccy Message95,799.471Cbreak
keith-44,497.53GBP-49,793.7419/05/2020 00:00:00Stmt Ccy Message595,117.405Cbreak
Malcolm-4,720.16EUR-4,720.1619/05/2020 00:00:00Stmt Ccy Message8,770.531Cbreak
Pierre-41.05PEN-10.9419/05/2020 00:00:00Stmt Ccy Message-41.0518Cwrite off
Arif-4.00ISK-0.0319/05/2020 00:00:00Stmt Ccy Message0.0051Cwrite off
Helena-0.16CZK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.162Cwrite off
Bard-0.09NOK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.404Cwrite off

But then writes over the data instead of dropping down into new tables:

FundCustody BalCurrencyEUR EquivDateFeed typeBluebay BalDayCountTeamComments
John-8,704,731.42GBP-9,740,791.1919/05/2020 00:00:00Stmt Ccy Message2,961,898.784AChased
Terry-2,061,400.19NZD-1,149,281.2119/05/2020 00:00:00Stmt Ccy Message36,621.574BFx
Antonia-1,181,792.59GBP-1,322,452.6219/05/2020 00:00:00Stmt Ccy Message625,207.414BFx
FundCustody BalCurrencyEUR EquivDateFeed typeBluebay BalDayCountTeamComments
John-8,704,731.42GBP-9,740,791.1919/05/2020 00:00:00Stmt Ccy Message2,961,898.784AChased
FundCustody BalCurrencyEUR EquivDateFeed typeBluebay BalDayCountTeamComments
Terry-2,061,400.19NZD-1,149,281.2119/05/2020 00:00:00Stmt Ccy Message36,621.574BFx
Antonia-1,181,792.59GBP-1,322,452.6219/05/2020 00:00:00Stmt Ccy Message625,207.414BFx
Arif-4.00ISK-0.0319/05/2020 00:00:00Stmt Ccy Message0.0051Cwrite off
Helena-0.16CZK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.162Cwrite off
Bard-0.09NOK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.404Cwrite off
FundCustody BalCurrencyEUR EquivDateFeed typeBluebay BalDayCountTeamComments
Arif-4.00ISK-0.0319/05/2020 00:00:00Stmt Ccy Message0.0051Cwrite off
Helena-0.16CZK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.162Cwrite off
Bard-0.09NOK-0.0119/05/2020 00:00:00Stmt Ccy Message-0.404Cwrite off
 
Upvote 0
Try:
VBA Code:
Sub team()
    Application.ScreenUpdating = False
    Dim LastRow As Long, team As Range, rngList As Object, key As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set rngList = CreateObject("Scripting.Dictionary")
    For Each team In Range("I2:I" & LastRow)
        If Not rngList.Exists(team.Value) Then
            rngList.Add team.Value, Nothing
        End If
    Next team
    For Each key In rngList
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Cells(1, 1).CurrentRegion.AutoFilter 9, key
        ActiveSheet.AutoFilter.Range.Copy Cells(LastRow + 3, 1)
    Next key
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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