我试图将excel VBA转换为ppt VBA。最初的excel VBA(" Comparison.xlsm")比较了其他excel工作簿中的值和Comparison.xlsm的Sheet1中打印的不匹配值。
我知道下面的代码(这是我的ppt VBA版本)正在查看正确的工作簿,因为当我使用MsgBox打印值时,我得到正确的。但是,我的问题是当我尝试将不正确的值打印到Comparison.xlsm的Sheet1中时:
mainWB.Worksheets("Sheet1").Range("A" & nextCell).Value = ID_ISS
mainWB.Sheets("Sheet1").Range("B" & nextCell).Value = "Symbol"
mainWB.Sheets("Sheet1").Range("B" & nextCell).Value = "(FCST)"
我只是看不到它在excel电子表格中打印。这是相关代码:
编辑:我更改了它以添加我的所有代码 -
Dim strIDRangeISS As String
Dim strIDRangeFCST As String
Dim iRow As Integer
Dim iCol As Integer
Dim ID_ISS As Long
Dim ID_FCST As Long
Dim nextCell As Integer
Dim iRowISS As Integer
Dim iRowFCST As Integer
Dim wbkFCST As Excel.Workbook
Dim wbkISS As Excel.Workbook
Dim mainWB As Excel.Workbook
Dim varSheetFCST As Excel.Worksheet
Dim varSheetISS As Excel.Worksheet
Dim mainWS As Excel.Worksheet
nextCell = 1
Set wbkFCST = Workbooks.Open("C:\Users\...\Documents\FCST.xlsx")
Set varSheetFCST = wbkFCST.Worksheets("Details")
Set wbkISS = Workbooks.Open(FileName:="C:\Users\...\Documents\ISS.xlsm")
Set varSheetISS = wbkISS.Worksheets("ISS")
Set mainWB = Workbooks.Open(FileName:="C:\Users\...\Documents\Comparison.xlsm")
Set mainWS = mainWB.Worksheets("Sheet1")
strIDRangeISS = "A2:D50"
strIDRangeFCST = "B2:I50"
'varSheetISS = varSheetISS.Range(strIDRangeISS)
'varSheetFCST = varSheetFCST.Range(strIDRangeFCST)
Dim ISSArray As Variant: ISSArray = varSheetISS.Range(strIDRangeISS)
Dim FCSTArray As Variant: FCSTArray = varSheetFCST.Range(strIDRangeFCST)
For iRowISS = LBound(ISSArray, 1) To UBound(ISSArray, 1) 'Goes down ISS' ID column
ID_ISS = ISSArray(iRowISS, 1)
MsgBox ("ID_ISS is " & ID_ISS)
For iRowFCST = LBound(FCSTArray, 1) To UBound(FCSTArray, 1) 'Goes down FCST ID column
ID_FCST = FCSTArray(iRowFCST, 1)
MsgBox ("ID_FCST is " & ID_FCST)
'Compares ISS ID to FCST ID till finds matching
If (ID_ISS = ID_FCST) Then
'If corr symbols aren't same, record ID in Comparison's spreadsheet and go onto next ISS ID
If (ISSArray(iRowISS, 3) <> FCSTArray(iRowFCST, 2)) Or (ISSArray(iRowISS, 4) <> FCSTArray(iRowFCST, 8)) Then
mainWB.Worksheets("Sheet1").Range("A" & nextCell).Value = ID_ISS
'Symbol mismatch
If (ISSArray(iRowISS, 3) <> FCSTArray(iRowFCST, 2)) Then
mainWB.Sheets("Sheet1").Range("B" & nextCell).Value = "Symbol"
End If
'(FCST) mismatch
If (ISSArray(iRowISS, 4) <> FCSTArray(iRowFCST, 8)) Then
mainWB.Sheets("Sheet1").Range("B" & nextCell).Value = "(FCST)"
End If
nextCell = nextCell + 1
End If
Exit For 'If corr symbols are same, go onto next ISS ID
End If
'Reached end of FCST ID's and no match -> record ISS ID
If iRowFCST = 49 Then
Workbooks("Comparison.xlsm").Sheets("Sheet1").Range("A" & nextCell).Value = ID_ISS
Workbooks("Comparison.xlsm").Sheets("Sheet1").Range("B" & nextCell).Value = "No corressponding Issue ID"
nextCell = nextCell + 1
Exit For
End If
Next iRowFCST
Next iRowISS