Function causing a little problem

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey all,

This function will allow only the alphanumeric characters when applied to a cell. However with new workbooks all goes well but with my old workbook the very function will cause the workbook to prompt user to save file, even though no changes are made to it. This can be a little annoying and I would like to make it go away. It is very clear that the function is causing this problem as removing it fixes the issue.

VBA Code:
Function AlphaNumericOnly(strSource As String) As String
    Dim i As Integer
    Dim strResult As String

    For i = 1 To Len(strSource)
        Select Case Asc(Mid(strSource, i, 1))
            Case 48 To 57, 65 To 90, 97 To 122: 'include 32 if you want to include space
                strResult = strResult & Mid(strSource, i, 1)
        End Select
    Next
    AlphaNumericOnly = strResult
End Function

Will appreicate a lot.
Thanks.
 
If I set up a sheet as you described here:

it works just fine for me. I do not get prompted to re-save the file when I open it and then try to close it.

So if you do not have a good, representative file that to upload that has this problem, then I really have nothing else to offer on this issue.

I suspect the problem is with something along the lines of:
- Other VBA code (especially if you have event procedure code or are messing around with calculation methods)
- You have a circular reference
Dear Joe ,
Thanks for looking into this.
Well, I was hoping it would give that prompt. I will going to check this with my other PC with different version of office installed and maybe post some relevent information.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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