总和如果VBA语法带有可变列? [英] Sum If VBA syntax with variable columns?

查看:297
本文介绍了总和如果VBA语法带有可变列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个字符串TargetCol,其中包含vlookup结果的列号,即B,C,D,E等.我希望我的SumIf语句查找字符串TargetCol中包含的值.以下是我正在使用的代码的一部分.我无法获得SumIF语句中& TargetCol"":"& TargetCol''部分的正确语法.

任何帮助将不胜感激.

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.

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



谢谢,
Vinayak


[edit]代码块已更改为VB以纠正语法着色-OriginalGriff [/edit]



Thanks,
Vinayak


[edit]Code block changed to VB to correct syntax coloring - OriginalGriff[/edit]

推荐答案

Formula替换FormulaR1C1.


这篇关于总和如果VBA语法带有可变列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆