我发现了一个与我非常接近的问题,但由于答案是针对该问题的,因此我无法将其与我的完全联系起来。
我正在使用 if not 函数来填充其中已经包含值的列,如果条件存在并且如果条件不存在,我希望它覆盖这些值,如果它们不存在,我希望它保持原样。
换句话说,我希望函数的“else”部分说skip或类似的东西......我已经尝试过“null”“skip”和其他一些但没有运气。
下面是我的代码的一部分,以防有必要忽略我的代码中的问题,这不是成品,只是在您需要一些变量的情况下的基本思想。先感谢您!:
Sub ReportCompareAlta() ' ' ReportCompareAlta Macro ' 添加 D 列为“ALTA”的实例
Dim varSheetA As Variant
Dim varSheetB As Variant
Dim varSheetC As Variant
Dim StrValue As Variant
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
Dim WbkA As Workbook
Dim WbkB As Workbook
Dim WbkC As Workbook
Dim counter As Long
Set WbkA = Workbooks.Open(Filename:="G:\Reporting\AH_MISSE_FEB2013.xls")
Set WbkB = Workbooks.Open(Filename:="G:\Reporting\AH_MISSE_MAR2013.xls")
Set WbkC = Workbooks.Open(Filename:="G:\Reporting\ReportCompare.xls")
Set varSheetA = WbkA.Worksheets("LocalesMallContratos")
Set varSheetB = WbkB.Worksheets("LocalesMallContratos")
Set varSheetC = WbkC.Worksheets("Sheet1")
strRangeToCheck = "A1:IV65536"
Debug.Print Now
varSheetA = WbkC.Worksheets("Sheet2").Range(strRangeToCheck) 'may be confusing code here
varSheetB = WbkC.Worksheets("Sheet3").Range(strRangeToCheck) 'may be confusing code here
Debug.Print Now
counter = 0
For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
If varSheetB(iRow, "B") = varSheetA(iRow, "B") & varSheetB(iRow, "B") <> "GERENCIA" & varSheetB(iRow, "B").Value <> "" & varSheetB(iRow, "D") = "ALTA" Then
StrValue = ""
varSheetB.Range("iRow:B").Select
Selection = StrValue
ActiveSheet = varSheetC
Range("A1").Select
Selection.Offset(counter, 0).Value = StrValue
counter = counter - 1
Else
"SKIP"
End If
Next iRow
结束子