我正在构建一个宏,它从下载的 .CVS 工作表中选择数据并将它们插入到现有工作簿中。下载的 .CVS 工作表具有名称“付款历史记录######-#_date”,其数字 (#) 对应于代表我的其他工作簿中的行的帐号。有60多个帐号。
这个想法是遍历包含帐号的范围,并使用类似的函数将帐号与工作表名称的数字部分匹配。它会是这样的:
'variables declared
For Each Row In Accounts 'Accounts references the range of account numbers in the other workbook
AccNumber = CStr(Rows.Cells(row, 1))
If sheet.name like "*AccNumber*" then
...code continues...
Next Row
我认为使用 like 函数是不可能的,它将一个字符串名称与固定模式进行比较。有替代方案/解决方法吗?
最佳答案
您可以使用 Instr
检查字符串比较是否返回值>0的函数,如果没有找到,它将使用以下代码返回-1,如果有任何问题,请告诉我,因为信息太有限:
For Each Row In Accounts.Cells 'Accounts references the range of account numbers in the other workbook
AccNumber = CStr(Rows.Value)
If InStr(Sheet.Name, AccNumber) > 0 Then
...code continues...
Next Row
关于excel - 将单元格值与工作表名称的一部分进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67986863/