PC Review


Reply
Thread Tools Rate Thread

Code to compare

 
 
acss
Guest
Posts: n/a
 
      1st Apr 2008
Is there code that would perform a compare btween two columns and should the
values not be the same then a yes/no message box can appear to alert the
user?
 
Reply With Quote
 
 
 
 
cht13er
Guest
Posts: n/a
 
      1st Apr 2008
On Apr 1, 5:45 pm, acss <joekr...@hotmail.com> wrote:
> Is there code that would perform a compare btween two columns and should the
> values not be the same then a yes/no message box can appear to alert the
> user?


Yes there is. It would likely look something like this...

Private Sub CompareColumns()

Dim iCounter as Integer
Dim bnSame as Boolean

Do For iCounter = 1 to 150 'this gets changed depending on how many
rows you want to compare
If Cells(iCounter,1).Value = Cells(iCounter,2).Value Then
'if any value in column A = in column B
bnSame = True
iCounter = 150 'don't keep checking
End If
Loop

If bnSame = True Then
Msgbox "At least one identical value"
End If

End Sub

Throw that into a new module once you are in the VBE (Ctrl+F11) ...
post back with any more questions!

HTH

Chris
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      2nd Apr 2008
Maybe if you could give me some more info. And what your data looks like in
the spreedsheet. I could cook you up something


"acss" wrote:

> Is there code that would perform a compare btween two columns and should the
> values not be the same then a yes/no message box can appear to alert the
> user?

 
Reply With Quote
 
acss
Guest
Posts: n/a
 
      2nd Apr 2008
It is really something simple like if user typed in column A the amount of
100 then Column b should automatically have that value and should it not
then a message box would appear or some sort of error flag.

"Mike" wrote:

> Maybe if you could give me some more info. And what your data looks like in
> the spreedsheet. I could cook you up something
>
>
> "acss" wrote:
>
> > Is there code that would perform a compare btween two columns and should the
> > values not be the same then a yes/no message box can appear to alert the
> > user?

 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      2nd Apr 2008
Sub somethingSimple()
Const whatColumn = "A" 'Change to your needs
Dim looper As Long 'looper = 5 Starting row of data
Dim lastToCheckRow As Long
Dim cellPointer As Variant

lastToCheckRow = Range(whatColumn & Rows.Count).End(xlUp).Row

For looper = 1 To lastToCheckRow
Set cellPointer = Worksheets("Sheet1").Cells(looper, 1)
If cellPointer <> cellPointer.Offset(0, 1) Then
MsgBox "Range(" & cellPointer.Address & ")" _
& " does not match Range(" & _
cellPointer.Offset(0, 1).Address & ")"
End If
Next looper
End Sub

"acss" wrote:

> It is really something simple like if user typed in column A the amount of
> 100 then Column b should automatically have that value and should it not
> then a message box would appear or some sort of error flag.
>
> "Mike" wrote:
>
> > Maybe if you could give me some more info. And what your data looks like in
> > the spreedsheet. I could cook you up something
> >
> >
> > "acss" wrote:
> >
> > > Is there code that would perform a compare btween two columns and should the
> > > values not be the same then a yes/no message box can appear to alert the
> > > user?

 
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
Any way to compare VBA code in different workbooks? =?Utf-8?B?Q2hlZXItUGhpbC1seQ==?= Microsoft Excel Programming 4 6th Jan 2007 02:45 AM
Compare and Reverse some code =?Utf-8?B?anVsaWFsYXR0ZQ==?= Microsoft Access Queries 0 4th May 2006 03:40 PM
Compare all VBA-code in two versions of same DB =?Utf-8?B?RGlhbmVQRGF2aWVz?= Microsoft Access VBA Modules 4 2nd Nov 2005 02:15 PM
Compare vb code in two databases? Rick Microsoft Access VBA Modules 0 16th Jul 2004 02:35 PM
Source Code Compare Doug Microsoft C# .NET 3 1st Feb 2004 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.