VBA sum the counts on different sheets to return the value in another sheet

SamCha

New Member
Joined
Nov 23, 2020
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I am trying to sum the counts in Sheet 2 (Range B:B) and Sheet 3 (Range B:B) and return the sum of the counts in Sheet 1 in Cell C2. The rows with value keeps varying in both the Sheets, However, for both the sheets the text (for eg abc) starts from Row 2.

Please can you help with a vba code for the above.

Thanks in advance.
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,651
Office Version
  1. 365
Platform
  1. Windows
Is this what you are looking for?
Excel Formula:
=SUM(Sheet2!B:B)+SUM(Sheet3!B:B)

If not, it might be helpful if you post some examples of your data along with your expected results, so that we can see exactly what you are after.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,651
Office Version
  1. 365
Platform
  1. Windows
Sorry, missed the VBA part. Here is a VBA solution that returns that value:
VBA Code:
Sub MySum()

    Dim rng1 As Range
    Dim rng2 As Range
    Dim tot As Double
    
    Set rng1 = Sheets("Sheet2").Columns("B:B")
    Set rng2 = Sheets("Sheet3").Columns("B:B")
    
    tot = Application.WorksheetFunction.Sum(rng1) + Application.WorksheetFunction.Sum(rng2)
    
    MsgBox tot
    
End Sub
 
Solution

SamCha

New Member
Joined
Nov 23, 2020
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Sorry, missed the VBA part. Here is a VBA solution that returns that value:
VBA Code:
Sub MySum()

    Dim rng1 As Range
    Dim rng2 As Range
    Dim tot As Double
   
    Set rng1 = Sheets("Sheet2").Columns("B:B")
    Set rng2 = Sheets("Sheet3").Columns("B:B")
   
    tot = Application.WorksheetFunction.Sum(rng1) + Application.WorksheetFunction.Sum(rng2)
   
    MsgBox tot
   
End Sub
Thanks a lot Joe4. This worked for me.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,651
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,581
Messages
5,625,612
Members
416,124
Latest member
DeMoNloK

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