Vba 两列上的左函数
我有一段代码:我想在下面的代码中对单元格G和M执行一个左函数:我在尝试时遇到了一个问题:Vba 两列上的左函数,vba,excel,excel-formula,Vba,Excel,Excel Formula,我有一段代码:我想在下面的代码中对单元格G和M执行一个左函数:我在尝试时遇到了一个问题: If left(.Cells(i, "G",4)) <> left(.Cells(i, "M",4)) this does not work. 如果左(.Cells(i,“G”,4))左(.Cells(i,“M”,4))这不起作用。 有什么建议吗 以下是完整的代码: Sub SingleTradeMove() Dim wsTD As Worksheet Set wsTD = Wor
If left(.Cells(i, "G",4)) <> left(.Cells(i, "M",4)) this does not work.
如果左(.Cells(i,“G”,4))左(.Cells(i,“M”,4))这不起作用。
有什么建议吗
以下是完整的代码:
Sub SingleTradeMove()
Dim wsTD As Worksheet
Set wsTD = Worksheets("Trade data")
Sheets("Sheet2").Range("A2:AK600").ClearContents
With wsTD
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lastRow
If .Cells(i, "G") <> .Cells(i, "M") _
Or .Cells(i, "I") <> .Cells(i, "O") _
Or .Cells(i, "L") <> .Cells(i, "R") Then
.Cells(i, "J").EntireRow.Copy _
Destination:=Sheets("Sheet2").Range("A" &
Rows.Count).End(xlUp).Offset(1)
End If
Next i
End With
End Sub
Sub-SingleTradeMove()
将wsTD设置为工作表
设置wsTD=工作表(“交易数据”)
纸张(“纸张2”)。范围(“A2:AK600”)。清晰内容
使用wsTD
lastRow=.Range(“A”&.Rows.Count).End(xlUp).Row
对于i=2到最后一行
If.单元格(i,“G”).单元格(i,“M”)_
或.单元格(i,“i”).单元格(i,“O”)_
或。单元格(i,“L”)。单元格(i,“R”)则
.Cells(i,“J”).EntireRow.Copy_
目的地:=板材(“板材2”)。范围(“A”&
行数)。结束(xlUp)。偏移量(1)
如果结束
接下来我
以
端接头
您需要使用
If left(.Cells(i, "G"),4) <> left(.Cells(i, "M"),4)
If left(.Cells(i,“G”),4)left(.Cells(i,“M”),4)
您需要使用
If left(.Cells(i, "G"),4) <> left(.Cells(i, "M"),4)
If left(.Cells(i,“G”),4)left(.Cells(i,“M”),4)
这可能不是最好的答案(这就是为什么我只把它作为一个注释保留下来),但你肯定可以这样做:strG=left(.Cells(I,“G”,4))
和strM=left(.Cells(I,“M”,4))
这样做如果strG-strM
。这可能不是最好的答案(这就是为什么我只把它作为注释保留下来)但是你当然可以这样做:strG=left(.Cells(i,“G”,4))
和strM=left(.Cells(i,“M”,4))
以便在strG-strM中执行操作。很好,出于某种原因,我只是假设在Cells()
中使用了正确数量的参数!很好,出于某种原因,我只是假设使用了Cells()
中正确数量的参数!