索引匹配功能VBA

时间:2019-02-11 12:05:53

标签: vba indexing match

我试图在我的VBA程序上使索引/匹配工作正常,但没有成功。 我正在尝试将“比较”中的A列与先前提取的“ A”列进行匹配,并返回K列。所有这些都在循环遍历每一行时进行。我已经测试了所有内容,并且一切正常。现在唯一的问题是使此索引/匹配有效。

Sub Delta_Analysis()

Dim wb As Excel.Workbook
Set wb = ThisWorkbook

Dim sheet_refresh_instructions As Excel.Worksheet
Set sheet_refresh_instructions = wb.Worksheets("Refresh instructions")

Dim sheet_previous_extract As Excel.Worksheet
Set sheet_previous_extract = wb.Worksheets("Previous extract")

Dim sheet_current_extract As Excel.Worksheet
Set sheet_current_extract = wb.Worksheets("Current extract")

Dim sheet_comparison As Excel.Worksheet
Set sheet_comparison = wb.Worksheets("Comparison")

Dim sheet_historical_changes As Excel.Worksheet
Set sheet_historical_changes = wb.Worksheets("Historical changes")

'Start manipulating objects

sheet_previous_extract.UsedRange.ClearContents
sheet_current_extract.UsedRange.Copy
sheet_previous_extract.Cells(1, 1).PasteSpecial Paste:=xlPasteValues
sheet_current_extract.UsedRange.ClearContents

sheet_refresh_instructions.Activate
Range("C6").Select

    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    Workbooks.Open Filename:= _
        "http://jira3.ms.com/jira/sr/jira.issueviews:searchrequest-excel-current-fields/53756/SearchRequest-53756.xls?tempMax=1000"
    ActiveWindow.Visible = False
    Windows("SearchRequest-53756.xls").Visible = False

Dim wb1 As Excel.Workbook
Set wb1 = Excel.Workbooks("SearchRequest-53756.xls")
Dim sheet_Jira As Excel.Worksheet
Set sheet_Jira = wb1.Worksheets("general_report")

sheet_Jira.Activate
sheet_Jira.Range("1:3").EntireRow.Delete
sheet_Jira.UsedRange.Copy

sheet_current_extract.Cells(1, 1).PasteSpecial Paste:=xlPasteValues

wb1.Close

With sheet_comparison
    .Range("A2:K" & .Cells(.Rows.Count, "A").End(xlUp).Row).ClearContents
End With

sheet_current_extract.Range("a2", sheet_current_extract.Range("a2").End(xlDown)).Copy
    Sheets("Comparison").Select
    Range("A2").Select
    ActiveSheet.Paste

Dim i As Integer
i = 2

Do While sheet_previous_extract.Cells(i, 1) <> ""

Cells(i, 2) = Application.WorksheetFunction.Index(sheet_previous_extract.Range("K:K"), Application.WorksheetFunction.Match(sheet_comparison.Range("A:A"), sheet_previous_extract.Range("A:A"), 0))

i = i + 1

Loop


End Sub

0 个答案:

没有答案