Solved

Adding to code

Posted on 2011-02-25
5
184 Views
Last Modified: 2012-05-11
Hi,

I have the below piece of code and i want to start adding more named ranges like "Today" and "Yesterday"

How can i add on to that code

e.g. my next named ranges would be "MeritToday" & "Merit Yesterday"

Thanks
Seamus
Option Explicit

Public Sub CompareData()
  'compares Today and Yesterday named ranges
  Dim rngToday As Range
  Dim rngYesterday As Range
  Dim rngTcell As Range
  Dim boolFirstTime As Boolean
  
  Set rngToday = ActiveSheet.Range("Today")
  Set rngYesterday = ActiveSheet.Range("Yesterday")
  
  If (rngToday.Columns.Count = rngYesterday.Columns.Count) _
    And (rngToday.Rows.Count = rngYesterday.Rows.Count) Then
  Else
    MsgBox "Sophis Fiscal are Identical!", vbCritical, "Range size difference"
    Exit Sub
  End If
  
  
  boolFirstTime = True
  For Each rngTcell In rngToday
    If rngTcell.Value <> rngYesterday.Cells(rngTcell.Row - rngToday.Row + 1, rngTcell.Column - rngToday.Column + 1).Value Then
    Else
      If boolFirstTime Then
        boolFirstTime = False   'skip header cell
      Else
        Exit Sub
      End If
    End If
  Next
  MsgBox "Data Identical", vbCritical, "Range Data Identical"
End Sub

Open in new window

0
Comment
Question by:Seamus2626
  • 3
  • 2
5 Comments
 
LVL 45

Expert Comment

by:patrickab
ID: 34981667
Seamus2626,

Try the code below to add the range names. Change the ranges to which each of them refer to suit your requirements.

Patrick
ActiveWorkbook.Names.Add Name:="MeritToday", RefersToR1C1:="=Sheet1!R1C1:R10C1"
    Range("B1:B10").Select
    ActiveWorkbook.Names.Add Name:="Merit Yesterday", RefersToR1C1:="=Sheet1!R1C2:R10C2"

Open in new window

0
 

Author Comment

by:Seamus2626
ID: 34981715
Hi Patrick, is not possible for me to simply name a range like the above code as opposed to having to reference each area?

Thanks
Seamus
0
 
LVL 45

Accepted Solution

by:
patrickab earned 500 total points
ID: 34983088
>is not possible for me to simply name a range like the above code as opposed to having to reference each area?

I don't understand the point you are making. Do please explain. The code  I gave can and will work.
0
 

Author Closing Comment

by:Seamus2626
ID: 34996155
Thanks Patrick

Seamus
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34996205
Seamus - Thanks for the grade - Patrick
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now