Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a string TargetCol that contains the column number of a vlookup result, namely B,C,D,E, etc. I want my SumIf statement to lookup the value contained in the string TargetCol. Below is an extract of the code I'm using. I'm unable to get the right syntax for the "&TargetCol"'":"'"&TargetCol"' part in the SumIF statement.

Any help would be highly appreciated.

VB
If Not rngFound Is Nothing Then
    rngAddress = rngFound.Address
    rngAddress1 = Trim(Left(rngAddress, 2))
    TargetCol = Trim(Right(rngAddress1, 1))
    'MsgBox "Match found at column: " & TargetCol

    For i = 5 To lastRow
     For k = 4 To 11
      If Cells(i, k) = "" Then

       Cells(i, k).FormulaR1C1 = "=SUMIF('Netting SAP - TCD'!C1:C1,'AK090N Trade Receivables'!RC1,'Netting SAP - TCD'!'"&TargetCol"'":"'"&TargetCol"')"

End If
     Next k
    Next i


Thanks,
Vinayak


[edit]Code block changed to VB to correct syntax coloring - OriginalGriff[/edit]
Posted
Updated 13-Jul-11 21:18pm
v3
Comments
Dr.Walt Fair, PE 14-Jul-11 0:24am    
Fixed the <pre> blocks

1 solution

Replace FormulaR1C1 with Formula.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900