Macro to find missing extensions

g2only

New Member
Joined
Oct 9, 2014
Messages
2
Hi, I'm a newbie...just to state that up front, please don't throw rocks! ;)

I'm a creative designer by trade, but have been getting into more 'expanded' requirements by clients.

Anyways, here's my question, I have an ongoing monthly gig that I'm supplied with a spreadsheet that includes multiple columns with field entries of file names (some_file.pdf). The problem is sometimes there are field entry missing the extension (.pdf) and up till now I've been having to find them manually. I did a search and haven't found anybody that's already made a macro to do so (just to save the "...did you search the forums, yet, dumb-dumb?" comments), so I was hoping an experienced macro-maker could lend me a hand.

Much appreciated in advanced!

George
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub findExtension()

    For Each cell In ActiveSheet.UsedRange
        If UCase(Right(cell, 4)) <> ".PDF" Then cell = cell & ".pdf"
    Next cell
End Sub

Try this. I used the usedRange because I don't know your columns...so it might attack other cells with the .pdf extension. Be sure to try this on a saved copy of your workbook so as not to endanger data.
 
Upvote 0
Thanks, NeonRedSharpie!

If I were to specify the columns, how would this code change?

(Columns D-I)
 
Last edited:
Upvote 0
Thanks, NeonRedSharpie!

If I were to specify the columns, how would this code change?

(Columns D-I)

Give this a go.

Code:
Sub findExtension()


    Dim startRow As Integer
    Dim maxRow As Long
    Dim startCol As Integer
    Dim endCol As Integer
    
    startCol = 4 '4 = D
    maxCol = 9 '9 = I
    startRow = 2 'THIS ASSUMES HEADERS. CHANGE TO 1 IF NO HEADERS
    maxRow = 0


    For x = startCol To maxCol
        If Cells(Rows.Count, x).End(xlUp).Row > maxRow Then
            maxRow = Cells(Rows.Count, x).End(xlUp).Row
        End If
    Next x


    For Each cell In Range(Cells(startRow, startCol), Cells(maxRow, maxCol))
        If cell.Value <> "" And UCase(Right(cell, 4)) <> ".PDF" Then cell = cell & ".pdf"
    Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,539
Messages
6,120,100
Members
448,944
Latest member
SarahSomethingExcel100

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