Hardcoding works but Variable doesnt in SUMIF

Subash.Raj

New Member
Joined
May 3, 2011
Messages
2
This looks like a fairly stupid question to ask and i've tried my way around the forum but couldn't find an answer that worked for me.

I am passing using FormulaR1C1 with a SUMIF. When I pass a hardcoded value into the Criteria, it seems to be working fine. But when I try to pass a variable, the variable value is getting captured correctly. However, the code doesn't work.

BE16 is the hardcoded value and the SALESORGNAME is the variable that isn't working.

Code:
Dim Name As String
    Dim SalesOrgName As String
    Dim found As Boolean
    Dim r As Integer
    Dim CovPercentage As String
    Dim CovPercentageTemp As String
    Sheets("Report").Select
    Name = Cells(3, "A").Value
    found = False
    Sheets("Sales Org").Select
    Range("I2").Select
    ' Set Do loop to stop at empty cell.
    r = 1
    Do Until IsEmpty(ActiveCell)
    ' Check active cell for search value.
    r = r + 1
        If ActiveCell.Value = Name Then
            found = True
            SalesOrgName = Cells(r, "J").Value
            Cells(3, "P").Value = SalesOrgName
     'Cells(3, "Q").FormulaR1C1 = _
        "=SUMIF('POS Coverage'!R2C3:R131C9,""BE16"",'POS Coverage'!R2C9:R131C9)"
    Cells(3, "Q").FormulaR1C1 = _
        "=SUMIF('POS Coverage'!R2C3:R131C9, " & SalesOrgName & ",'POS Coverage'!R2C9:R131C9)"
'        Cells(3, "Q").FormulaR1C1 = _
        "=SUMIF('POS Coverage'!R2C3:R131C9,'POS Coverage'!R2C9:R131C9,""BE16"")"
            CovPercentageTemp = Cells(3, "Q").Value
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
SalesOrgName needs to be in double quotes, try this.
Code:
 "=SUMIF('POS Coverage'!R2C3:R131C9, """ & SalesOrgName & """,'POS Coverage'!R2C9:R131C9)"
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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