【问题标题】:concatenate range of cells in RC style notation vba macros以 RC 样式表示法 vba 宏连接单元格范围
【发布时间】:2017-07-14 22:05:12
【问题描述】:

我正在为我的班级项目执行线性插值。我创建了一个插值函数并且必须动态执行计算,因为每个问题的列数都不同。因此,我检索了最后一列(ltr)的值并尝试将其与 R1C1 格式连接起来。但它不起作用。您能否提出一些想法,如何解决此问题。 请在下面找到以下代码:

Private Sub TrialCheck_Click() 
    Dim lrt As Double 
    With ActiveSheet 
         'retrives last column i.e lrt = 447
        lrt = .Cells(.Rows.Count, "F").End(xlUp).Row 
    End With 
    Range("I3").Value = Range("F3").Value * Range("B3").Value 
    Range("I58").Value = Range("F" & lrt).Value * Range("B58").Value 
     'MacroR
     'following works as 447 is hardcoded
     'Range("I4").Value = _
    "=(LinInterp(RC[-8],R4C[-4]:R447C[-4],R4C[-3]:R447C[-3])*RC[-7])" 
     'following code doesn't concatenate value of lrt
    Range("I4").Value = _ 
    "=(LinInterp(RC[-8],R4C[-4]:R&lrt&C[-4],R4C[-3]:R&lrt&C[-3])*RC[-7])" 
    Range("J4").Select 

    Range("I4").AutoFill Destination:=Range("I4:I57"), Type:=xlFillDefault 
    Range("I4:I57").Select 
End Sub 

【问题讨论】:

    标签: vba excel concatenation


    【解决方案1】:

    你必须做字符串连接

    "string" & lrt & "string" & lrt & "string"
    
    Range("I4").Value = _ 
    "=(LinInterp(RC[-8],R4C[-4]:R" & lrt & "C[-4],R4C[-3]:R" & lrt & "C[-3])*RC[-7])" 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多