【发布时间】:2014-01-08 08:39:27
【问题描述】:
我有两张工作表,一张包含历史数据,另一张包含我刚刚导入的数据。我想检查现有数据以查看新数据是否包含任何重复的引号(因此会被“转换”为订单)。
目前我正在获取 A2 中的报价单,并使用以下代码将其与其他工作表中的报价单进行比较:
Dim wb As Workbook
Set wb = ActiveWorkbook
Dim wS As Worksheet
Set wS = ActiveSheet
Dim importWS as worksheet
importWS = sheets.("NEWDATA")
select.importWS
Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
'Set the current quote number as a value to be located
Dim valueToFind As Long
valueToFind = ActiveCell.Value
Dim checkRange As Range
Set checkRange = wS.Range("D1:D" & EntryRow)
'Check the existing worksheet to see if the quote already exists
Dim xlCell As Range
For Each xlCell In checkRange
If xlCell.Value = valueToFind Then
problems:
Dim existQuote As range
existQuote = xlCell.Address
Dim existingRow As Integer
existingRow = existingQuote.Row
MsgBox valueToFind & "in row" & existingRow & "has been converted to an order"
End If
Next xlCell
Loop Until ActiveCell.Value > 300000 Or ActiveCell.Value = ""
ActiveCell.Offset(-1, 0).Select
Dim DataPoints As Integer
DataPoints = ActiveCell.Row
ActiveCell.Offset(1, 0).Select
我在“问题:”处遇到了 if 函数问题 该代码成功识别出重复的报价编号,但我希望它检查同一行中的另一个单元格是否=“销售订单”,然后基于此执行操作。
我想不出一种方法来使用此代码获取我所在单元格的行号,以便我可以检查它并编辑条目。
编辑:.address 函数返回 string,而不是 range。这就是它失败的原因。
【问题讨论】: