【发布时间】:2020-08-02 11:19:30
【问题描述】:
我正在尝试为命名变量 a 和 b 输入动态公式。该公式将包含以下逻辑:如果 a(定义如下)为空白,则 b(定义如下)否则为 a。应将结果输入到名为 Client ID 的新列中。我能够创建新列客户端 ID,但由于需要调试代码停止的公式,因此遇到了问题。 我试图以不同的方式定义我的变量和范围,但仍然有问题。
感谢任何帮助。谢谢!
Sub baSTEP1formulaINDEV()
'A column named Client ID already exists
Dim sht As Worksheet
Dim StartCell As Range
Dim LastR As Long
Dim LastC As Long
Set sht = Worksheets("Group Activity")
Set StartCell = Range("A1")
Dim a As Integer
a = Cells.Find(What:="*Client: Client / Contact ID*", After:=Range("A2"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
ActiveWindow.Activate
Dim b As Integer
b = Cells.Find(What:="*Case Participant Client ID*", After:=Range("A2"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
ActiveWindow.Activate
'Find Last Row and Column
LastR = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row
LastC = sht.Cells(StartCell.Row, sht.Columns.Count).End(xlToLeft).Column
Range(Selection).Formula = _
"=IF(ISBLANK(a),b,a)"
End Sub
【问题讨论】:
标签: excel vba dynamic excel-formula