Cách So sánh nội dung 2 File Excel nhanh chóng

ngananh652

New member
## Cách so sánh nội dung của 2 tệp excel một cách nhanh chóng

** #Excel #data #Comparison #Bảng tính **

So sánh nội dung của hai tệp Excel có thể là một nhiệm vụ tẻ nhạt, đặc biệt nếu các tệp lớn.Tuy nhiên, có một vài cách để làm cho quá trình dễ dàng hơn.

### 1. Sử dụng tính năng ** So sánh **

Cách dễ nhất để so sánh hai tệp Excel là sử dụng tính năng ** so sánh **.Để thực hiện việc này, hãy mở cả hai tệp và nhấp vào tab ** dữ liệu **.Trong dải băng ** dữ liệu **, nhấp vào nút ** so sánh **.

Điều này sẽ mở hộp thoại ** So sánh **.Trong hộp thoại ** so sánh **, bạn có thể chọn các tệp bạn muốn so sánh.Bạn cũng có thể chọn bảng bạn muốn so sánh và cột bạn muốn so sánh.

Khi bạn đã chọn các tệp và tờ bạn muốn so sánh, nhấp vào nút ** So sánh **.Điều này sẽ tạo ra một sổ làm việc mới cho thấy sự khác biệt giữa hai tệp.

Sổ làm việc mới sẽ có hai tờ.Tờ đầu tiên sẽ hiển thị sự khác biệt giữa hai tệp.Tờ thứ hai sẽ hiển thị sự tương đồng giữa hai tệp.

### 2. Sử dụng công cụ của bên thứ ba

Nếu bạn cần so sánh hai tệp Excel thường xuyên hơn, bạn có thể muốn xem xét sử dụng công cụ của bên thứ ba.Có một số công cụ khác nhau có sẵn, mỗi công cụ có bộ tính năng riêng.

Một số công cụ phổ biến bao gồm:

* [Excel so sánh] (https://www.extendoffice.com/product/excel-compare.html)
* [Datadiff] (https://www.datadiff.com/)
* [DiffChecker] (https://www.diffchecker.com/)

Các công cụ này có thể làm cho quá trình so sánh các tệp Excel dễ dàng hơn nhiều, đặc biệt là nếu các tệp lớn hoặc phức tạp.

### 3. Sử dụng macro VBA

Nếu bạn cảm thấy thoải mái với VBA, bạn cũng có thể tạo một macro để so sánh hai tệp Excel.Đây có thể là một cách hiệu quả hơn để so sánh các tệp, đặc biệt nếu bạn cần so sánh các tệp một cách thường xuyên.

Để tạo một macro VBA, hãy mở tệp Excel mà bạn muốn sử dụng làm mẫu.Sau đó, nhấp vào tab ** Nhà phát triển **.Trong ruy băng ** nhà phát triển **, nhấp vào nút ** Visual Basic **.

Điều này sẽ mở Trình chỉnh sửa Visual Basic.Trong trình soạn thảo Visual Basic, tạo một mô -đun mới.Trong mô -đun, dán mã sau:

`` `
Sub so sánhfiles ()

Dim WB1 như sổ làm việc
Dim WB2 như sổ làm việc
Dim WBK như sổ làm việc
Dim WS1 như bảng tính
Dim WS2 như bảng tính
Dim Rng1 dưới dạng phạm vi
Dim rng2 dưới dạng phạm vi
Dim tôi dài
Dim J dài

'Đặt các biến cho hai sổ làm việc.
WB1 = ActiveWorkbook
wb2 = workbooks.open ("c: \ path \ to \ file2.xlsx")

'Đặt các biến cho hai bảng tính.
ws1 = wb1.sheets ("sheet1")
ws2 = wb2.Sheets ("sheet1")

'Đặt các biến cho các phạm vi để so sánh.
rng1 = ws1.range ("a1: c10")
rng2 = ws2.range ("a1: c10")

'So sánh hai phạm vi.
Cho i = 1 đến rng1.rows.count
Cho j = 1 đến rng1.columns.count
Nếu rng1.cells (i, j) <> rng2.cells (i, j) thì
MSGBOX "Các giá trị tại" & rng1.cells (i, j) .address & "và" & rng2.cells (i, j) .address & "là khác nhau."
Kết thúc nếu
Tiếp theo j
Tiếp theo tôi

'Đóng sổ làm việc thứ hai.
wb2.close

Kết thúc phụ
`` `

Macro này sẽ so sánh hai phạm vi được chỉ định và hiển thị hộp thông báo nếu bất kỳ giá trị nào khác nhau.

### Mẹo để so sánh các tệp excel

* Khi so sánh hai tệp Excel, điều quan trọng là đảm bảo rằng các tệp ở cùng định dạng.
=======================================
## How to compare the content of 2 Excel files quickly

**#Excel #data #Comparison #spreadsheet**

Comparing the content of two Excel files can be a tedious task, especially if the files are large. However, there are a few ways to make the process easier.

### 1. Use the **Compare** feature

The easiest way to compare two Excel files is to use the **Compare** feature. To do this, open both files and click on the **Data** tab. In the **Data** ribbon, click on the **Compare** button.

This will open the **Compare** dialog box. In the **Compare** dialog box, you can choose which files you want to compare. You can also choose which sheets you want to compare, and which columns you want to compare.

Once you have selected the files and sheets you want to compare, click on the **Compare** button. This will create a new workbook that shows the differences between the two files.

The new workbook will have two sheets. The first sheet will show the differences between the two files. The second sheet will show the similarities between the two files.

### 2. Use a third-party tool

If you need to compare two Excel files more frequently, you may want to consider using a third-party tool. There are a number of different tools available, each with its own set of features.

Some popular tools include:

* [Excel Compare](https://www.extendoffice.com/product/excel-compare.html)
* [Datadiff](https://www.datadiff.com/)
* [Diffchecker](https://www.diffchecker.com/)

These tools can make the process of comparing Excel files much easier, especially if the files are large or complex.

### 3. Use a VBA macro

If you are comfortable with VBA, you can also create a macro to compare two Excel files. This can be a more efficient way to compare files, especially if you need to compare the files on a regular basis.

To create a VBA macro, open the Excel file that you want to use as the template. Then, click on the **Developer** tab. In the **Developer** ribbon, click on the **Visual Basic** button.

This will open the Visual Basic Editor. In the Visual Basic Editor, create a new module. In the module, paste the following code:

```
Sub CompareFiles()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim wbk As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim i As Long
Dim j As Long

' Set the variables for the two workbooks.
wb1 = ActiveWorkbook
wb2 = Workbooks.Open("C:\path\to\file2.xlsx")

' Set the variables for the two worksheets.
ws1 = wb1.Sheets("Sheet1")
ws2 = wb2.Sheets("Sheet1")

' Set the variables for the ranges to compare.
rng1 = ws1.Range("A1:C10")
rng2 = ws2.Range("A1:C10")

' Compare the two ranges.
For i = 1 To rng1.Rows.Count
For j = 1 To rng1.Columns.Count
If rng1.Cells(i, j) <> rng2.Cells(i, j) Then
MsgBox "The values at " & rng1.Cells(i, j).Address & " and " & rng2.Cells(i, j).Address & " are different."
End If
Next j
Next i

' Close the second workbook.
wb2.Close

End Sub
```

This macro will compare the two specified ranges and display a message box if any of the values are different.

### Tips for comparing Excel files

* When comparing two Excel files, it is important to make sure that the files are in the same format.
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock