excel - 如何用函数输出替换范围,并覆盖范围值?
问题描述
我有一个看起来像这样的 vba 代码,试图用函数 FuzzyVLookup 的输出替换一个单元格,目前,我可以读取单元格 mAr(i,1) 并有一个 FuzzyVLookup(mAr(i,1) 的输出, inRng1 ,1) 但我无法覆盖最初的 mAr(i,1)
提前感谢您的帮助
Public Sub Test()
Dim StartTime As Double
Dim MinutesElapsed As String
'Remember time when macro starts
StartTime = Timer
'---------------------------------------------------------------
'-- Select Range A for comparison to be compared with Range B --
'---------------------------------------------------------------
Const LBLS As String = "Names to be matched "
Const xNAME As String = "Fuzzy Match Lead"
Set inRng = Application.Selection
Set inRng = Application.InputBox(LBLS, xNAME, inRng.Address, Type:=8)
'-----------------------------------------------
'-- Select Range B for Range A to be compared --
'-----------------------------------------------
Const LBLS1 As String = "Names to be matched to "
Const xNAME1 As String = "Fuzzy Match Source"
Set inRng1 = Application.Selection
Set inRng1 = Application.InputBox(LBLS1, xNAME1, inRng.Address, Type:=8)
If inRng.Columns.Count > 1 Or inRng.Areas.Count > 1 Then
MsgBox "Please select a single (continuous) column"
Exit Sub
End If
allRows = inRng.Rows.Count
If inRng.Count = 1 Then 'if only one cell selected force mAr to array
ReDim mAr(1, 1)
mAr(1, 1) = inRng.Value2
Else
mAr = inRng.Value2
End If
For i = 1 To allRows
mAr(i, 1) = FuzzyVLookup(mAr(i, 1), inRng1, 1)
Next
inRng = mAr 'place memory array back to range
'Determine how many seconds code took to run
MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
'Notify user in seconds
MsgBox "This code ran successfully in " & MinutesElapsed & " minutes", vbInformation
End Sub
解决方案
推荐阅读
- flutter - 在初始化器 baseTextStyle 中只能访问静态成员
- dfa - Epsilon 转换如何用于 NFA 到 DFA 的转换?
- python - 在窗口中创建坐标查找
- javascript - 使用 JavaScript 悬停鼠标移动
- swift - 将 ImageData 从一个视图控制器传递到另一个视图控制器
- c# - 如何在 View .Net Core 中呈现 JavaScript 的实际脚本
- phoenix-framework - 在“插入”中的类型不匹配:整数
- r - 运行包含中文的R脚本时,“运行选择”和“源”给出不同的结果
- android - 如何将应用程序从手机移动到 android Studio?
- php - Codeigniter 以正确的方式路由