LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default checking variances in cells

Adapt following to your needs...

Hopefully you understand the referencing...
rng() is defined as an array of ranges.

rng(0) is the row for the report.
rng(1) is used for the first range in each sheet
rng(2) is used for the second.

rng(1)(irow,1) is a short notation for: rng(1).Cells(irow,1)


I've added hyperlinks for simple navigation.




Sub VarianceGenerator()
Const shName = "Index"
Const r1Addr = "B2:B57"
Const r2Addr = "D2:D57"

Dim wksRep As Worksheet
Dim rng(2) As Range
Dim iWks&, iRow&, iVar&

On Error Resume Next
Set wksRep = Worksheets(shName)
On Error GoTo 0
If wksRep Is Nothing Then
Set wksRep = Worksheets.Add(befo=1)
wksRep.Name = shName
End If

With wksRep
'Make sure the report is the first worksheet
If .Index < 1 Then .Move befo=1

.UsedRange.Clear
.Cells(1, 1) = "Variance Report"
.Cells(2, 1) = "'" & Now
Set rng(0) = .Cells(4, 1).Resize(1, 3)
rng(0) = Array("Hyperlink", "Value A", "Value B")
End With

'Test that the constants are set properly
Debug.Assert Range(r1Addr).Columns.Count = 1 And _
Range(r2Addr).Columns.Count = 1 And _
Range(r1Addr).Rows.Count = Range(r2Addr).Rows.Count

'Walk the sheets
For iWks = 2 To Worksheets.Count
Set rng(1) = Worksheets(iWks).Range(r1Addr)
Set rng(2) = Worksheets(iWks).Range(r2Addr)
'Walk the rows of the ranges
For iRow = 1 To rng(1).Rows.Count
If StrComp(rng(1)(iRow, 1), rng(2)(iRow, 1), vbTextCompare) Then
iVar = iVar + 1
With rng(0).Offset(iVar)
.Value = Array(, rng(1)(iRow, 1), rng(2)(iRow, 1))
.Cells(1, 1).Formula = _
"=HYPERLINK(""#" & Worksheets(iWks).Name & "!" & _
rng(1)(iRow, 1).Address(0, 0) & """)"
End With

End If
Next
Next

End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


koala wrote:


Is anyone able to assist with the following.

I have numerous spreadsheets in a workbook. (the amount always varies,
but usually between 40 and 50)

I need to check the contents of B2 against D2, B3 against D3 and so
down to B57 against D57. (for each of the sheets in the workbook). Note
Column B & D are “text”, and case does not matter, only content.

I then require a report (on another sheet called “variance report”)
that lists only those cells that differ:

When there is a difference, the report needs to show:

Sheet Name
Column A Value (Date)
Column B Value
Column D Value

I can post a small sample if needed.

Hoping someone is able to assist me with this assignment

Thanks in advance

Regards
Koala



 
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
variances Sue Excel Discussion (Misc queries) 1 August 21st 09 01:41 AM
Calculating Variances using formulas Carl Excel Worksheet Functions 1 February 13th 09 05:23 AM
Delta Variances by Period MrRJ Excel Discussion (Misc queries) 8 February 10th 09 08:51 PM
Splitting cells with significant variances from row to row Carolina Excel Discussion (Misc queries) 2 December 2nd 08 06:04 PM
Checking the Cells in Sheet1 with Cells in Sheet2 and replace Checking the cells in Sheet1 with Sheet2 Excel Worksheet Functions 1 August 19th 06 09:29 AM


All times are GMT +1. The time now is 12:06 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"