LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Compare Two Workbooks

I'm trying to write a piece of VBA that will check each cell in a workbook
against each corresponding cell in another workbook, and highlight where
there are differences.

I'm really falling over at the first hurdle, as I cant get my head around
how to reference the cells.

I've got variables that tell me the workbook, the worksheet, the row and the
column, but I don't appear able to so something as simple as check if
wb1.ws1.cell1 = wb2.ws2.cell2.

The code I have so far is below:

Sub test()

Dim wb1 As Workbook
Dim wb1name As String
Dim wb2 As Workbook
Dim wb2name As String
Dim ws1 As Worksheet
Dim ws1name As String
Dim ws2 As Worksheet
Dim ws2name As String
Dim cell1 As Range
Dim cell2 As Range
Dim cell1row As Long
Dim cell1column As Long
Dim cell2row As Long
Dim cell2column As Long
Dim filelocation As String
Dim strCurrentworkbook As String
Dim strpreviousworkbook As String

filelocation = Workbooks("Position Check
Model20100305.xls").Worksheets("phase2").Range("d" & 16)
strCurrentworkbook = Workbooks("Position Check
Model20100305.xls").Worksheets("phase2").Range("d" & 17)
strpreviousworkbook = Workbooks("Position Check
Model20100305.xls").Worksheets("phase2").Range("d" & 18)

'open currentworkbook
ChDir filelocation
Workbooks.Open Filename:=strCurrentworkbook
'open previousworkbook
Workbooks.Open Filename:=strpreviousworkbook

Set wb1 = Workbooks(strCurrentworkbook)
Set wb2 = Workbooks(strpreviousworkbook)

For Each ws1 In wb1.Worksheets
ws1.Activate
ws1name = ActiveSheet.Name
ws2name = ws1name

For Each cell1 In ws1.UsedRange
cell1row = cell1.Row
cell1column = cell1.Column

MsgBox (ws1name & ", " & cell1row & ", " & cell1column)

Next cell1

Next ws1

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare workbooks Andy Excel Discussion (Misc queries) 11 April 5th 09 11:46 PM
VBA to compare workbooks SteveDB1 Excel Programming 1 December 12th 08 08:46 PM
Compare workbooks Scafidel Excel Discussion (Misc queries) 2 May 28th 07 09:15 PM
compare different workbooks kjstec Excel Worksheet Functions 1 October 17th 06 06:34 PM
COMPARE 2 WORKBOOKS dgr Excel Programming 0 November 7th 05 09:59 AM


All times are GMT +1. The time now is 09:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"