0
對於excel,我對於VBA來說相當新。我想創建一個宏來比較兩個單獨的工作簿,然後顯示它們之間的差異。更多細節我會說,唯一需要比較的是兩個工作簿中的列A.任何意見將不勝感激。用於比較VBA Excel的工作簿的宏
對於excel,我對於VBA來說相當新。我想創建一個宏來比較兩個單獨的工作簿,然後顯示它們之間的差異。更多細節我會說,唯一需要比較的是兩個工作簿中的列A.任何意見將不勝感激。用於比較VBA Excel的工作簿的宏
這將做你想要的!
Public Sub CompareSheets()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim cell As Range, rng As Range
Set ws1 = Workbooks.Open("C:\your_path_here\Book1.xlsx").Sheets(1)
Set ws2 = Workbooks.Open("C:\your_path_here\Book2.xlsx").Sheets(1)
Set rng = ws1.Range("A1:A20")
For Each cell In rng
Celladdress = cell.Address
If cell <> ws2.Range(Celladdress) Then
cell.Interior.Color = vbYellow
ws2.Range(Celladdress).Interior.Color = vbYellow
End If
Next cell
End Sub
這只是強調了每個工作簿的列電子表格1,但是,對嗎?我運行它時不會比較紙張。 – Matthew
參考https://stackoverflow.com/documentation/excel-vba/777/getting-started-with-excel-vba#t=201705300004209262522 – YowE3K
的Excel 2013+配備了電子表格比較工具https://開頭support.office.com/en-us/article/Basic-tasks-in-Spreadsheet-Compare-f2b20af8-a6d3-4780-8011-f15b3229f5d8 – Slai