Sumifs Using Name Manager (Looking to change more dynamic)

RudRud

Active Member
Joined
Feb 2, 2023
Messages
275
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Hello, Gurus.

Monthly dataset for months 1, months 2, months 3 ( will add a new dataset every month)

Sheet 5 is a total based on the months (Months 1,2,3) for selected column ( Amounting & Totalling)

I've been using List Manager with VBA code, but whenever the name of a column changes, I have to rename it to reflect the new name (for example, if an end user writes Amounted, I must change it to Amounting).

I'm seeking for other references that are more convenience and more practical.

P.S. : users sometime put the column into row 2 - 5 and i'm unsure how to write in formula (both formula / VBA code will do)

Month1:
Book2
ABCD
1NamingColAmountingTotalling
2Rud123
3An222
4Rud235
5An222
Month1


Month2:
Book2
ABCD
1TotallingColNamingAmounting
231Rud2
322An2
452Rud3
522An2
Month2


Month3:
Book2
ABCD
1ColAmountingTotallingNaming
2123Rud
3222An
4235Rud
5222An
Month3


Dict:
Book2
ABCDEFG
1AmountingamouMonth11amou1=Month1!$C:$C
2TotallingtotaMonth22amou2=Month2!$D:$D
3NamingnameMonth33amou3=Month3!$B:$B
4name1=Month1!$A:$A
5name2=Month2!$C:$C
6name3=Month3!$D:$D
7tota1=Month1!$D:$D
8tota2=Month2!$A:$A
9tota3=Month3!$C:$C
10
11
12
13
dict


You may run the namemng, listname code to appear Column F & G

1685096509185.png


Total
Book2
ABCDEFG
1AmountingAmountingAmountingTotallingTotallingTotalling
2NameMonth1Month2Month3Month1Month2Month3
3Rud555888
4An444444
Sheet5
Cell Formulas
RangeFormula
B3:B4B3=SUMIFS(amou1,name1,A3)
C3:C4C3=SUMIFS(amou2,name2,A3)
D3:D4D3=SUMIFS(amou3,name3,A3)
E3:E4E3=SUMIFS(tota1,name1,A3)
F3:F4F3=SUMIFS(tota2,name2,A3)
G3:G4G3=SUMIFS(tota3,name3,A3)
Named Ranges
NameRefers ToCells
amou1=Month1!$C:$CB3:B4
amou2=Month2!$D:$DC3:C4
amou3=Month3!$B:$BD3:D4
name1=Month1!$A:$AE3:E4, B3:B4
name2=Month2!$C:$CF3:F4, C3:C4
name3=Month3!$D:$DG3:G4, D3:D4
tota1=Month1!$D:$DE3:E4
tota2=Month2!$A:$AF3:F4
tota3=Month3!$C:$CG3:G4


VBA Code:
Sub namemngbook2()
Dim i%, S%
Dim bArr()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

On Error Resume Next

bArr = ThisWorkbook.Sheets("dict").Range("a1").CurrentRegion.Value
shtname = ThisWorkbook.Sheets("dict").Range("d1").CurrentRegion.Value
'shtname = ThisWorkbook.Sheets("dict").Range("d1").Value

For S = 1 To UBound(shtname, 1)

    For i = 1 To UBound(bArr, 1)
 
        found = ThisWorkbook.Sheets(shtname(S, 1)).Cells.Find(what:=bArr(i, 1)).Address
        ActiveWorkbook.Names.Add Name:=bArr(i, 2) & shtname(S, 2), RefersToR1C1:=ThisWorkbook.Sheets(shtname(S, 1)).Range(found).EntireColumn
     
    Next i

Next S

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic



End Sub
Sub DeleteNMbook2()
Dim i%, S%

Dim RangeName As Name


On Error Resume Next
For Each RangeName In Names
    ActiveWorkbook.Names(RangeName.Name).Delete
Next
On Error GoTo 0

 ThisWorkbook.Sheets("dict").Range("f1:g1500").Value2 = ""


End Sub

Sub listnamebook2()
Application.ScreenUpdating = False
ThisWorkbook.Sheets("dict").Range("f1").ListNames
End Sub
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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