PC Review


Reply
Thread Tools Rate Thread

Compare Column Headings

 
 
=?Utf-8?B?UEpGcnk=?=
Guest
Posts: n/a
 
      28th Aug 2007
I have a spreadsheet that users paste a report into and I want to make sure
the data are in the correct columns. (Many of the reports provided to my
group have a similar layout, making it easy to make a mistake if you are not
paying close attention.)

Here is what I have:

Sub FindCol()
Sheets("Data").Select
Range("A1").Select
If ActiveCell.Value = "TC #" Then
Range("F1").Select
If ActiveCell.Value = "Dept #" Then
Exit Sub

Else

MsgBox ("Incorrect Value in Cell " & Range(ActiveCell.Row & ":" &
ActiveCell.Column))

End If
End If

End Sub

Two issues:
1) The MsgBox is supposed to return the location of the incorrect cell, but
I get a type mismatch error. What do I need to do to convert the range to a
string?

2) Is there a better way to go about this? This works fine on two cells,
but if I ever want to add more, it will become increasingly difficult.

Thanks!
PJ
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      29th Aug 2007
Give this a whirl... It is expandable by copying just the one line and
chaning the range and value to be checked. It also selects the incorrect cell
and lets the user know what the value should be...

Sub FindCol()
with Sheets("Data")
.Select
If CheckHeading(.Range("A1"), "TC #" ) Then Exit Sub
If CheckHeading(.Range("F1"), "Dept #") Then Exit Sub 'Copy this line ***
end with
End Sub

Private Function CheckHeading(ByRef rng As Range, _
ByVal strHeading As String) As Boolean

If UCase(Trim(rng.Value)) <> UCase(strHeading) Then
rng.Select
MsgBox "This heading is wrong. It should be """ & strHeading &
""".", vbCritical
CheckHeading = True
Else
CheckHeading = False
End If

End Function
--
HTH...

Jim Thomlinson


"PJFry" wrote:

> I have a spreadsheet that users paste a report into and I want to make sure
> the data are in the correct columns. (Many of the reports provided to my
> group have a similar layout, making it easy to make a mistake if you are not
> paying close attention.)
>
> Here is what I have:
>
> Sub FindCol()
> Sheets("Data").Select
> Range("A1").Select
> If ActiveCell.Value = "TC #" Then
> Range("F1").Select
> If ActiveCell.Value = "Dept #" Then
> Exit Sub
>
> Else
>
> MsgBox ("Incorrect Value in Cell " & Range(ActiveCell.Row & ":" &
> ActiveCell.Column))
>
> End If
> End If
>
> End Sub
>
> Two issues:
> 1) The MsgBox is supposed to return the location of the incorrect cell, but
> I get a type mismatch error. What do I need to do to convert the range to a
> string?
>
> 2) Is there a better way to go about this? This works fine on two cells,
> but if I ever want to add more, it will become increasingly difficult.
>
> Thanks!
> PJ

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      29th Aug 2007
Try this:-

MsgBox ("Incorrect Value in Cell " & ActiveCell.Address)

I'll think about your other question.

Regards,

OssieMac

"PJFry" wrote:

> I have a spreadsheet that users paste a report into and I want to make sure
> the data are in the correct columns. (Many of the reports provided to my
> group have a similar layout, making it easy to make a mistake if you are not
> paying close attention.)
>
> Here is what I have:
>
> Sub FindCol()
> Sheets("Data").Select
> Range("A1").Select
> If ActiveCell.Value = "TC #" Then
> Range("F1").Select
> If ActiveCell.Value = "Dept #" Then
> Exit Sub
>
> Else
>
> MsgBox ("Incorrect Value in Cell " & Range(ActiveCell.Row & ":" &
> ActiveCell.Column))
>
> End If
> End If
>
> End Sub
>
> Two issues:
> 1) The MsgBox is supposed to return the location of the incorrect cell, but
> I get a type mismatch error. What do I need to do to convert the range to a
> string?
>
> 2) Is there a better way to go about this? This works fine on two cells,
> but if I ever want to add more, it will become increasingly difficult.
>
> Thanks!
> PJ

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      29th Aug 2007
MsgBox "Incorrect Value in Cell " & ActiveCell.Address(0,0)

--
Regards,
Tom Ogilvy



"PJFry" wrote:

> I have a spreadsheet that users paste a report into and I want to make sure
> the data are in the correct columns. (Many of the reports provided to my
> group have a similar layout, making it easy to make a mistake if you are not
> paying close attention.)
>
> Here is what I have:
>
> Sub FindCol()
> Sheets("Data").Select
> Range("A1").Select
> If ActiveCell.Value = "TC #" Then
> Range("F1").Select
> If ActiveCell.Value = "Dept #" Then
> Exit Sub
>
> Else
>
> MsgBox ("Incorrect Value in Cell " & Range(ActiveCell.Row & ":" &
> ActiveCell.Column))
>
> End If
> End If
>
> End Sub
>
> Two issues:
> 1) The MsgBox is supposed to return the location of the incorrect cell, but
> I get a type mismatch error. What do I need to do to convert the range to a
> string?
>
> 2) Is there a better way to go about this? This works fine on two cells,
> but if I ever want to add more, it will become increasingly difficult.
>
> Thanks!
> 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
Compare Column Headings and Delete Nonmatch bthurman Microsoft Excel Programming 1 2nd Feb 2009 08:46 PM
Worksheet has numeric column headings. Change to alpha headings? Be Frank Microsoft Excel Misc 1 18th Jun 2008 04:22 PM
Column headings to numbers and row headings to alphabets? Juliana Microsoft Excel Misc 2 9th May 2008 05:58 PM
Using Row headings instead of Column Headings with DoCmd.TransferSpreadsheet rblivewire@hotmail.com Microsoft Access External Data 12 7th Jan 2007 07:07 PM
Can I invert a table so row headings are now column headings etc =?Utf-8?B?U2hhcm9u?= Microsoft Excel Worksheet Functions 3 10th Feb 2005 07:28 PM


Features
 

Advertising
 

Newsgroups
 


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