excel - 比较列然后在最后一行之后添加文本
问题描述
所以我试图将一个工作表上的 g1:g51 与 m11:m15 进行比较,如果找到匹配项,则跳过“M”中的下一个空白并插入“G”中的下一个文本,它在 wsDest.Range("M" ) = 不匹配2。我究竟做错了什么?
Dim wsCopy As Worksheet
Dim wsCopy3 As Worksheet
Dim i2 As Integer
Dim inrow2 As Integer
Dim inmatch2 As String
Dim k2 As Integer
Dim outrow2 As Integer
Dim outmatch2 As String
'Set variables for copy and destination sheets
Set wsCopy = Worksheets("Sheet1")
Set wsCopy3 = Worksheets("Sheet3")
If wsCopy3.Range("b1") > 0 Then
inrow2 = 10
For i2 = 1 To inrow2
inmatch2 = wsCopy.Range("a" & i2)
If inmatch2 = "" Then Exit For
outrow2 = 25
For k2 = 1 To outrow2
outmatch2 = wsCopy3.Range("b" & k2)
If outmatch2 = inmatch2 Then
Exit For
End If
If outmatch2 = "" Then
wsCopy3.Range("b" & k2) = inmatch2
Exit For
End If
Next
If outmatch2 = "" Then
Exit For
End If
Next
End If
End Sub
解决方案
Sub ADDING() Dim wsCopy As Worksheet Dim wsCopy3 As Worksheet Dim i2 As Integer Dim inrow2 As Integer Dim inmatch2 As String Dim k2 As Integer Dim outrow2 As Integer Dim outmatch2 As String
'Set variables for copy and destination sheets
Set wsCopy = Worksheets("Sheet1")
Set wsCopy3 = Worksheets("Sheet3")
If wsCopy3.Range("b1") > 0 Then
inrow2 = 10
For i2 = 1 To inrow2
inmatch2 = wsCopy.Range("a" & i2)
If inmatch2 = "" Then Exit For
outrow2 = 25
For k2 = 1 To outrow2
outmatch2 = wsCopy3.Range("b" & k2)
If outmatch2 = inmatch2 Then
Exit For
End If
If outmatch2 = "" Then
wsCopy3.Range("b" & k2) = inmatch2
Exit For
End If
Next
If outmatch2 = "" Then
Exit For
End If
Next
End If
结束子
推荐阅读
- angular - 当我更改页面时,ionViewDidLeave 和 ionViewDidEnter 没有触发
- vb6 - 如何将应用程序带到最前面?
- javascript - 跨域发送信息,不接触服务器端
- oauth-2.0 - Spring 对 OIDC 工作流的原生支持
- php - 在 laravel 查询生成器中加入多个表会导致重复
- javascript - 无法读取未定义的属性“TUT”?
- macos - MacOS在运行kafkacat时抛出dyld错误
- c - 如何获取变量 n1 以在最后一个 while 循环下执行计算并打印转换次数(变量:noc)?
- python - 迭代 3D 数组中的元素会给出错误的元素
- java - 解决了无论如何要在方法中不创建另一个扫描仪的情况下做到这一点?