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.
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