SUM cells with a specific column header from multiple worksheets - Using VBA

isanka88

New Member
Joined
Dec 12, 2020
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi All Good people

I'm new to VBA and I'm seeking some assistance with a macro. I have a workbook with multiple sheets. First worksheet is call master worksheet. In the master worksheet I have sheet names. I would like to sum all cells below a specific column header named, "My text." across all my worksheets and insert the sum values in master sheet. For an example lets suppose I have 4 worksheets as Master, Shee1, Sheet2 and Sheet3. In the Master sheet I have each sheet names from A1 to C1. So I want the sum value below each of these sheet names. The sum value should pull from sheet 1, 2 & 3 based on heading name "My Text" But the column is dynamic in position (doesn't always fall under the same column or row)

Is there a way to find the term "My text" and sum all cells that fall under that column header?

Please let me know if I can provide any additional details to help with my request. I have attached my original workbook as below with my requirement explained on it

https://drive.google.com/file/…wDb1_C5Llb7eGOoDD1TH/view

Thanks in advance for your help!
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
610
Office Version
  1. 365
Platform
  1. Windows
Hi. Try this code.
VBA Code:
Sub GetSums()
 Dim lngCol As Long, wsName As Range
  With Sheets("Master")
   If .[C3] <> "" Then .Range("C3", .[B3].End(2)) = ""
   For Each wsName In .Range("C2", .[B2].End(2))
    lngCol = Sheets(wsName.Value).Rows(1).Find("My Text").Column
     wsName.Offset(1).Value = _
      Evaluate("Sum('" & wsName.Value & "'!" & Cells(3, lngCol + 1).Address & ":" & _
       Sheets(wsName.Value).Cells(Rows.Count, lngCol + 1).End(3).Address & ")")
   Next wsName
  End With
End Sub
 

isanka88

New Member
Joined
Dec 12, 2020
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Osvaldo
I do not know what to say and how to thank you. this is awesomely worked for me. My happiness is out of verbal definitions. You guys are amazing. Because of valuable people like you, Life is very easy for beginners like us. Thank you soo much for this. I owe you a lot for this.:love::love::love::love::love::love::love:
 

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
610
Office Version
  1. 365
Platform
  1. Windows
Hi, Isanka.
Thank you very much for your kind words and for your feedback.
We're glad to have contributed in some way to solve your demand. :)
Have a great weekend.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,281
Messages
5,600,720
Members
414,401
Latest member
grenona2020

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
Top