ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Verify Data Format via VB (https://www.excelbanter.com/excel-programming/296477-re-verify-data-format-via-vbulletin.html)

Bob Phillips[_6_]

Verify Data Format via VB
 
Hi Mike,

Here is some code to get you started

Sub Check()
Dim i As Long

For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(i, "A").Value < "" Then
If Not IsNumeric(Cells(i, "A").Value) Then
Cells(i, "A").Interior.ColorIndex = 3
End If
End If
Next i

For i = 1 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value < "" Then
If Not IsDate(Cells(i, "B").Value) Then
Cells(i, "B").Interior.ColorIndex = 3
End If
End If
Next i

For i = 1 To Cells(Rows.Count, "C").End(xlUp).Row
If Cells(i, "C").Value < "" Then
If IsNumeric(Cells(i, "B").Value) Then
Cells(i, "C").Interior.ColorIndex = 3
End If
End If
Next i

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mike" wrote in message
...
Hi all.

Searched for this with no joy. I have a worksheet with data in columns

that are either dates, numbers or free text. The worksheet is processed by a
second application which doesn't run any syntax checks, so i am trying to
implement a syntax check myself (it is possible ot generate this data
worksheet this data in the wrong columns).
Thus, i am trying to create a VB macro that will check, for example, that

all entries in column A are numbers, all entries in column B are dates etc
etc.
Not getting much joy googl'ing it either.
TIA

Mike




mike

Verify Data Format via VB
 
Many thanks Bob
I'll give that a try soon

Mike


All times are GMT +1. The time now is 01:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com