General discussion

Locked

Data verification

By GCHeels ·
I have an Excel spreadsheet I would like to export data out of to Access. The only problem is that the data to be exported changes occasionally. I would like to write a macro that looks at a cells' contents and verifies that a text entry is there and it is the one I expected, continues on to the next cell to verify what is there. If the data doesn't match, I would like to display a message and stop the macro execution. The data would look similar to this:

Denver 450 250
Atlanta 350 150
New York 500 200

I want to verify that Denver is in cell A1, Atlanta is in cell A2, New York is in cell A3.

If it is, continue with the data export. If it is not, display a message stating that "Data is not formatted correctly" and stop macroexecution. Thanks.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Data verification

by FirstPeter In reply to Data verification

Try this:

Sub Validate_Format()
If (Range("A1").Value <> "Denver" Or Range("A2").Value <> "Atlanta" Or Range("A3").Value <> "New York") Then
MsgBox "Data is not formatted correctly", vbCritical, "Format Error"
Exit Sub
End If

' Your success result code runs here

End Sub

That will check cells A1, A2, and A3 for the referenced cities. There are ways to make it more flexible, but this should meet your needs.

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums