ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with SUMIF in VBA (https://www.excelbanter.com/excel-programming/395806-help-sumif-vba.html)

[email protected]

Help with SUMIF in VBA
 
For one of my projects for work I have to add on to a VBA program that
someone else has written. I'm new to VBA and I've learned a lot over
the last few weeks but I need some help with this code. First of all,
what is the format for SUMIF and what does it do? Also, can someone
help me decipher this code? It's part of a much larger file but I'll
just post a piece of it here, hopefully someone can at least give me
an idea of what it is doing. I know that the code is pulling values
from somewhere, I'm just not sure where and how to modify it. Thank
you so much!

Dim colIndex, rwIndex, numofchems
Range("a5").Select
ActiveCell.FormulaR1C1 = "=counta(RC[1]:R[100]C[1])" 'Counts # of
different chemicals
numofchems = ActiveCell.Value
For colIndex = 3 To 7
For rwIndex = 5 To (numofchems + 4)
If colIndex = 3 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-1],'806UPWFinal2.XLS'!Organicyr)"
If colIndex = 4 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-2],'806UPWFinal2.XLS'!
Organiclbws)"
If colIndex = 5 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-3],'806UPWFinal2.XLS'!Organicgws)"
If colIndex = 6 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-4],'806UPWFinal2.XLS'!Organicppm)"
If colIndex = 7 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-5],'806UPWFinal2.XLS'!OrganicCOD)"
Next rwIndex
Next colIndex


Bob Phillips

Help with SUMIF in VBA
 
You have the format for SUMIF in your code.

It simply checks a range for a particular value, and sums a second range
where there is a match. The two ranges can be the same. But this is all
explained in help.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
oups.com...
For one of my projects for work I have to add on to a VBA program that
someone else has written. I'm new to VBA and I've learned a lot over
the last few weeks but I need some help with this code. First of all,
what is the format for SUMIF and what does it do? Also, can someone
help me decipher this code? It's part of a much larger file but I'll
just post a piece of it here, hopefully someone can at least give me
an idea of what it is doing. I know that the code is pulling values
from somewhere, I'm just not sure where and how to modify it. Thank
you so much!

Dim colIndex, rwIndex, numofchems
Range("a5").Select
ActiveCell.FormulaR1C1 = "=counta(RC[1]:R[100]C[1])" 'Counts # of
different chemicals
numofchems = ActiveCell.Value
For colIndex = 3 To 7
For rwIndex = 5 To (numofchems + 4)
If colIndex = 3 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-1],'806UPWFinal2.XLS'!Organicyr)"
If colIndex = 4 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-2],'806UPWFinal2.XLS'!
Organiclbws)"
If colIndex = 5 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-3],'806UPWFinal2.XLS'!Organicgws)"
If colIndex = 6 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-4],'806UPWFinal2.XLS'!Organicppm)"
If colIndex = 7 Then Cells(rwIndex, colIndex) =
"=SUMIF('806UPWFinal2.XLS'!tool,RC[-5],'806UPWFinal2.XLS'!OrganicCOD)"
Next rwIndex
Next colIndex





All times are GMT +1. The time now is 07:40 PM.

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