Oberon70
Board Regular
- Joined
- Jan 21, 2022
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
I have the below data as an example. The amount of data can change with the statement I copy from. So, I was wondering how do I go about creating a dynamic range that will consolidate the data or how do I change the Marco below so that it uses dynamic ranges?
Below is the code I received from Record Marco
And below is the end result
Cell Formulas | ||
---|---|---|
Range | Formula | |
B2:B36 | B2 | =VLOOKUP(A2,Statement_Data,6,FALSE) |
C2:C36 | C2 | =VLOOKUP(A2,Statement_Data,7,FALSE) + VLOOKUP(A2,Statement_Data,9,FALSE) |
D2:D36 | D2 | =B2-C2 |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
Statement_Data | =data!$A$2:$V$36 | B2:C36 |
Below is the code I received from Record Marco
VBA Code:
Sub Consolidate()
'
' Consolidate Macro
'
'
Range("I2").Select
Application.CutCopyMode = False
Selection.Consolidate Sources:= _
"'C:\Downloads\[VBA Project - Dummy file.xlsm]Receipt'!R2C1:R36C4", Function _
:=xlSum, TopRow:=False, LeftColumn:=True, CreateLinks:=False
End Sub
And below is the end result
VBA Project - Dummy file.xlsm | ||||||
---|---|---|---|---|---|---|
I | J | K | L | |||
2 | 295678410 | -$50.00 | -$38.50 | -$11.50 | ||
3 | 394308240 | $150.00 | $115.50 | $34.50 | ||
4 | 889035494 | $30.00 | $23.10 | $6.90 | ||
5 | 939394939 | $2,020.00 | $1,555.40 | $464.60 | ||
6 | 848593874 | $50.00 | $38.50 | $11.50 | ||
7 | 239394838 | $50.00 | $38.50 | $11.50 | ||
8 | 38299999 | $40.00 | $30.80 | $9.20 | ||
9 | 675768476 | $4.82 | $3.71 | $1.11 | ||
10 | 545496854 | $424.96 | $327.22 | $97.74 | ||
11 | 111111111 | $10.00 | $7.70 | $2.30 | ||
12 | 545485848 | $40.00 | $30.80 | $9.20 | ||
13 | 485848584 | $40.00 | $30.80 | $9.20 | ||
14 | 340145338 | $500.00 | $385.00 | $115.00 | ||
15 | 222222222 | $10.00 | $7.70 | $2.30 | ||
16 | 768576757 | $20.00 | $15.40 | $4.60 | ||
17 | 99495848 | $100.00 | $77.00 | $23.00 | ||
18 | 909945984 | $10.00 | $7.70 | $2.30 | ||
19 | 359489584 | $3.02 | $2.32 | $0.70 | ||
20 | 878574757 | $51.76 | $39.85 | $11.91 | ||
Receipt |