ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro for sumif formula (https://www.excelbanter.com/excel-programming/366137-macro-sumif-formula.html)

supamari0

macro for sumif formula
 
I currently have an excel document that uses the sumif formula. Currently, it
checks column E for a specific word (in this case "Hydrogen") It then takes
all the rows with "hydrogen" and adds up the numbers in the N column for
those respective rows.

My problem is that I need to turn this process into a macro rather than
relying on a formula. Any direction on how to code this? I know it should be
fairly simple but I'm a VBA novice.

Thanks in advance!


Toppers

macro for sumif formula
 
Sub MySumif()
Range("A1") = Application.SumIf(Range("E:E"), "Hydrogen", Range("N:N"))
End mySumif

You could change "Hydrogen" to reference a cell e.g. X1

Range("A1") = Application.SumIf(Range("E:E"), Range("X1"),Range("N:N"))

HTH

"supamari0" wrote:

I currently have an excel document that uses the sumif formula. Currently, it
checks column E for a specific word (in this case "Hydrogen") It then takes
all the rows with "hydrogen" and adds up the numbers in the N column for
those respective rows.

My problem is that I need to turn this process into a macro rather than
relying on a formula. Any direction on how to code this? I know it should be
fairly simple but I'm a VBA novice.

Thanks in advance!



All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com