"Mismatch" on a VBA string help

lloydie8

New Member
Joined
Sep 5, 2017
Messages
23
Hi guys

I have the below code, but I am getting a mismatch error on line 11. Any ideas? I'm a newbie to all this so it's got me stumped!

Code:
Sub GetLatestFiles()    Dim strDir As String, fs As Object, startFolder As String, subfolder As Object, increment As Integer, latest As Integer, latestFolder As String


    Set fs = CreateObject("Scripting.FileSystemObject")
    startFolder = "H:\Everyone\SOFTCON PCS"
    Set folder = fs.GetFolder(startFolder)
    latest = 0
    latestFolder = vbNullString        


    For Each subfolder In folder.SubFolders
        increment = CInt(VBA.Right(subfolder.Path, Len(subfolder.Path) - WorksheetFunction.Find("-", subfolder.Path, 1)))


        If increment > latest Then
            latest = increment
            latestFolder = subfolder.Path
        End If
    Next


    Workbooks.Open latestFolder & "\" & "EGBCIS13.txt"
End Sub

Thanks,
Gareth
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
you could have highlighted line 11. My line 11 is a blank line. Or do you mean the 11th line of code, not spaces.
and is the SUB the 1st line? or the code inside the sub?
 
Last edited:
Upvote 0
Sorry,

Copying from Notepad has messed with the formatting a wee bit.

The line that's mismatched is "increment = CInt(VBA.Right(subfolder.Path, Len(subfolder.Path) - WorksheetFunction.Find("-", subfolder.Path, 1)))"

Many thanks,
Gareth
 
Last edited:
Upvote 0
I assume whatever the result of your Right function is cannot be converted to an integer.
 
Upvote 0

Forum statistics

Threads
1,215,753
Messages
6,126,674
Members
449,327
Latest member
John4520

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