PC Review


Reply
Thread Tools Rate Thread

Compare Range Totals After VBA Manipulation

 
 
=?Utf-8?B?UEpGcnk=?=
Guest
Posts: n/a
 
      29th Aug 2007
I have a workbook in which users dump in data, run a macro and use the
result. The macro itself works great, but the users need to go the original
data to confirm that the totals still match.

Here is the process:
Users dump data into the 'Data' tab (original, huh?)
Run Macro
Compare the total value on the 'Output' tab to the 'Data' tab to make they
match.

Here is what I am thinking, but don't know how to code:

Dim x As Double
Dim y As Double

x = SUM(Sheets("Data").Range("F2:F50000"))
y = SUM(Sheets("Output").Range("Q2:Q50000"))

If x<>y Then
MsgBox "Totals do not match"
End If

Thoughts?

PJ
 
Reply With Quote
 
 
 
 
Jason
Guest
Posts: n/a
 
      29th Aug 2007
It looks like that would work if you placed
"Application.WorksheetFunction." in front of the SUM statement.


On Aug 29, 11:38 am, PJFry <PJ...@discussions.microsoft.com> wrote:
> I have a workbook in which users dump in data, run a macro and use the
> result. The macro itself works great, but the users need to go the original
> data to confirm that the totals still match.
>
> Here is the process:
> Users dump data into the 'Data' tab (original, huh?)
> Run Macro
> Compare the total value on the 'Output' tab to the 'Data' tab to make they
> match.
>
> Here is what I am thinking, but don't know how to code:
>
> Dim x As Double
> Dim y As Double
>
> x = SUM(Sheets("Data").Range("F2:F50000"))
> y = SUM(Sheets("Output").Range("Q2:Q50000"))
>
> If x<>y Then
> MsgBox "Totals do not match"
> End If
>
> Thoughts?
>
> PJ





 
Reply With Quote
 
=?Utf-8?B?UEpGcnk=?=
Guest
Posts: n/a
 
      29th Aug 2007
That did it. I also had to add a rounding function to x and y. It was
showing a variance of something like 5.31654-11.

x As Double
y As Double

Here is what I ended up with:
x = Application.WorksheetFunction.Sum(Sheets("Data").Range("AI:AI"))

y = Application.WorksheetFunction.Sum(Sheets("Upload").Range("C:C"))

If Round(x, 2) <> Round(y, 2) Then
MsgBox "Totals between the Data tab and the Upload tab do not match.",
vbOKOnly, "Total Error"
MsgBox "The file creation has been halted. Please correct the error and
rerun.", vbOKOnly
Exit Sub
End If


"Jason" wrote:

> It looks like that would work if you placed
> "Application.WorksheetFunction." in front of the SUM statement.
>
>
> On Aug 29, 11:38 am, PJFry <PJ...@discussions.microsoft.com> wrote:
> > I have a workbook in which users dump in data, run a macro and use the
> > result. The macro itself works great, but the users need to go the original
> > data to confirm that the totals still match.
> >
> > Here is the process:
> > Users dump data into the 'Data' tab (original, huh?)
> > Run Macro
> > Compare the total value on the 'Output' tab to the 'Data' tab to make they
> > match.
> >
> > Here is what I am thinking, but don't know how to code:
> >
> > Dim x As Double
> > Dim y As Double
> >
> > x = SUM(Sheets("Data").Range("F2:F50000"))
> > y = SUM(Sheets("Output").Range("Q2:Q50000"))
> >
> > If x<>y Then
> > MsgBox "Totals do not match"
> > End If
> >
> > Thoughts?
> >
> > PJ

>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to compare totals and flag those less than or more than Moz Microsoft Excel Misc 1 26th Mar 2010 04:41 PM
Compare Totals Dennis Chou Microsoft Access 3 18th Sep 2009 10:51 PM
Need some help with more effective range manipulation =?Utf-8?B?aGF2b2NkcmFnb24=?= Microsoft Excel Programming 7 24th Aug 2006 08:19 PM
Compare 2 totals queries =?Utf-8?B?Ymx1ZWJveTE4OTQ=?= Microsoft Access Queries 3 17th May 2006 09:37 AM
Range manipulation shishi Microsoft Excel Programming 1 4th Aug 2005 08:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:38 PM.