Need Macro to Check Format of Cells In A Column

dcofer

Board Regular
Joined
Jun 25, 2004
Messages
203
Hell All,

I need a macro, preferably, but a formula might work to check the contents of the cells in Column C of my report, which is usually about a thousand rows long.

The format should be like this example: 08-12-2017 DCV It needs a two digit month, a dash, a two digit day of the month, a dash, and a four digit year, followed by one space and the letters DCV in all caps.

The macro can simply check the third and sixth positions for a dash, the 11th position for a space and the twelfth, thirteenth and fourteenth position for the letters "DCV" in all caps.

Thanks in advance for your assistance.

David
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this
It will put either OK or Nope into Column D
Code:
Sub Ccheck()
' dcofer
    Dim Cnt As Long
    
    For Cnt = 2 To Range("C" & Rows.Count).End(xlUp).Row
        If Range("C" & Cnt).Value Like "##-##-#### DCV" Then
            Range("D" & Cnt) = "ok"
        Else
            Range("D" & Cnt) = "Nope"
        End If
    Next Cnt

End Sub
 
Upvote 0
Fluff,

Thanks for your help. But this put NOPE on every entry and most are correct. I reviewed the macro, and it looks like it would work.

Any idea why it put NOPE for every entry?
 
Upvote 0
Are the contents of col C actual values, or are they the result of a formula?
 
Upvote 0
Are the contents of col C actual values, or are they the result of a formula?

They are actual values.

I was able to write a formula and then using the macro recorder, I recorded a macro which works.

My macro is below:

Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+F
'
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.ColumnWidth = 6.44
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Range("D1").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(MID(RC[-1],3,1)=""-"",MID(RC[-1],6,1)=""-"",MID(RC[-1],11,1)="" "",MID(RC[-1],12,3)=""DCV""),""YES"",""NO"")"
Range("D1").Select
Selection.AutoFill Destination:=Range("D1:D335")
Range("D1:D335").Select
Range("D1:D335").Copy
Range("D1:D335").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub


Thanks for your time and assistance.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,857
Members
452,676
Latest member
woodyp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top