【问题标题】:Compare two workbooks for differencies cell by cell and colouring differencies in second workbook VBA在第二个工作簿 VBA 中逐个单元格比较两个工作簿的差异和着色差异
【发布时间】:2020-09-17 11:39:28
【问题描述】:

我尝试比较我在 excel 中使用两个不同按钮放置的两个工作簿,然后使用第三个按钮比较并将第二个工作簿中的所有差异涂成红色。我很新,但我的工作需要它,我目前已完成将两个具有相似代码的文件添加到两个按钮中:

Sub openDialogTemplate()
    Dim ofd As Office.FileDialog
    Dim temwb As Workbook
    Set ofd = Application.FileDialog(msoFileDialogFilePicker)

   With ofd

      .AllowMultiSelect = False
      .Title = "Please select the Template file."
      .Filters.Clear
      .Filters.Add "Excel 2003", "*.xlsx"
      .Filters.Add "All Files", "*.*"
      If .Show = True Then
        textFileName = .SelectedItems(1)
      End If
      Workbooks.Open Filename:=textFileName
      Set temwb = ActiveWorkbook
   End With
End Sub

Sub openDialogMaster()
    Dim fd As Office.FileDialog
    Dim maswb As Workbook
        
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

   With fd

      .AllowMultiSelect = False
      .Title = "Please select the Master file."
      .Filters.Clear
      .Filters.Add "Excel 2003", "*.xlsx"
      .Filters.Add "All Files", "*.*"
      If .Show = True Then
        txtFileName = .SelectedItems(1)
      End If
      Workbooks.Open Filename:=txtFileName
      Set maswb = ActiveWorkbook
   End With
End Sub

我不知道如何使用 temwb 和 maswb 中的工作簿正确编写循环,以逐个单元格地进行,并将第二个工作簿中的每个不同单元格涂成红色。

【问题讨论】:

  • 我假设您的第二个工作簿(您要在其中混合单元格的那个)是 Master 工作簿?另外,两个工作簿是否会有相同的数据集?你能提供你的 2 张纸的样本吗?

标签: excel vba colors compare


【解决方案1】:

我不确定这是否是正确的方法。当第一个工作簿中的单元格与第二个工作簿中的单元格不同时,我最好使用条件格式来突出显示单元格。

您可以在Microsoft Support找到更多信息

【讨论】:

  • 我完全同意你的回答。但是,特别是 Microsoft 和一般网站倾向于重新排列或以其他方式 404 网页。请edit您的帖子包含来自链接站点的一些相关详细信息,以帮助 OP。这是在 SO 回答问题时的预期和必需活动。不过,我会注意到,当事情重新安排时,维护Conditional Formatting 可能会成为一场噩梦,因为它不允许使用Named Ranges - 一个可悲的疏忽,正确编写代码可以 解决。
猜你喜欢
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
  • 2019-05-19
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多