2013-05-02 71 views
0

我發現真正接近我的,但作爲答案的問題是具體到我不能完全將它與我的問題。如果不是......否則跳過

我正在使用一個if函數來填充已經有值的列,我希望它覆蓋值,如果條件存在,如果他們不希望它離開它的價值如何。

換句話說,我想要的功能的「其他」部分說跳躍或類似的東西...我已經試過「空」,「跳過」和其他幾個人,但沒有運氣。

下面是情況下,我的代碼部分忽略我的代碼問題,這是不是最終產品,以防萬一你需要一些變量的基本思路是必要的。謝謝你在前進!:

子ReportCompareAlta() ' ' ReportCompareAlta宏 「再添實例,其中列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 

末次

回答

2

簡單地刪除ELSE:

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 

    End If  
+0

感謝幫助@nullptr – 2013-05-03 13:33:09

1

如前所述,你可以省略,其他部分。

如果你想真正看到一個「跳過」,你可以這樣做:

Else 
    Debug.Print "SKIP" 
End If 

這將顯示在立即窗口「跳過」(按Ctrl + G

相關問題