excel - 将两个工作表中的数据与 vba 中的主键匹配(发生错误 91)
问题描述
我尝试匹配两个工作表中的数据。我在每个工作表中都有一个主键和一列分配的数据。目标是匹配分配的数据而不在第三个工作表中显示主键。我也愿意接受其他解决方案的想法。非常感谢!
在调试模式下,该行:
lgfindRow = ThisWorkbook.Sheets("Labeltexte").Columns(1).Find(strPIN, lookat:=xlWhole, LookIn:=xlValues, MatchCase:=True).row
突出显示。
完整的子:
Sub MatchData()
Dim datasheet As Worksheet
Dim lgCount As Long
Dim intlastRow As Integer
Dim strPIN As String
Dim intcolumn As Integer
Dim intcheck As Integer
Dim intrange As Integer
Dim lgfindRow As Long
Dim intcancel As Integer
Set datasheet = ThisWorkbook.Worksheets("Produktdaten")
intlastRow = ThisWorkbook.Sheets("Artikelnummern").UsedRange.SpecialCells(xlCellTypeLastCell).row
For lgCount = 1 To intlastRow
intcolumn = 3
intcheck = 1
intcancel = 0
strPIN = ThisWorkbook.Sheets("Artikelnummern").Cells(lgCount, 1).Value
datasheet.Cells(lgCount, 1).Value = strPIN
datasheet.Cells(lgCount, 2).Value = ThisWorkbook.Sheets("Artikelnummern").Cells(lgCount, 2).Value
lgfindRow = ThisWorkbook.Sheets("Labeltexte").Columns(1).Find(strPIN, lookat:=xlWhole, LookIn:=xlValues, MatchCase:=True).row**
Do Until ThisWorkbook.Sheets("Labeltexte").Cells(lgfindRow + intcheck, 1).Value <> "" Or intcancel = 10
intcheck = intcheck + 1
intcancel = intcancel + 1
Loop
For intrange = 0 To intcheck - 1
datasheet.Cells(lgCount, intcolumn).Value = ThisWorkbook.Sheets("Labeltexte").Cells(lgfindRow + intrange, 2).Value
intcolumn = intcolumn + 1
Next
Next
End Sub
解决方案
推荐阅读
- ssis - SSIS - 数据流 - 如何拆分 0 行返回?
- node.js - Promise.all 和 .map 返回 null
- python - 基数为 10 的 int() 的无效文字:'[7' 以及如何删除括号
- css - 如何修改此图形 Angular 字符
- performance - 高 Web 卸载时间 - 它会影响 Time To First Byte 指标吗?
- sql - SQL 仅从另一个表中的选项拆分总计
- excel - VBA 函数只产生零。无法弄清楚为什么
- java - Regex Java 允许数字、字母、特殊字符(一些)
- excel - 通过定义的标题字符串识别列号(忽略大写、小写、缩进)
- javascript - 如何将 javascript 变量的内容设置为文本文件的内容?