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.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Where exactly have you placed these formulas?
In which cells?
Can you post a small sample of your data that contains the cells that these formulas reference?
I copied the first formula in A1 and the second one in A2.
I'll be surprised if it doesn't give you a prompt on close.
 
Upvote 0
If you are putting the first formula in cell A1:
Rich (BB code):
=IF(OR(M1="(All)",M1=""),"",OFFSET(A1,-1,0)+1)
Then you may be creating a circular reference, since you have A1 in that formula reference.
Also, since cell A1 is the first cell on the sheet, you cannot move up one row (-1).

I suspect this is your issue.
 
Upvote 0
If you are putting the first formula in cell A1:
Rich (BB code):
=IF(OR(M1="(All)",M1=""),"",OFFSET(A1,-1,0)+1)
Then you may be creating a circular reference, since you have A1 in that formula reference.
Also, since cell A1 is the first cell on the sheet, you cannot move up one row (-1).

I suspect this is your issue.
No I created this file just to demo the save prompt problem.
My original file will not begin from A1 but A5. For instance A5 to A10 then row 11 is all blank then A12 to A20 and so on and so forth.

I want the serial numbering to reset after each blank row. for instnce at A12 begin from 1 again.
I am posting here one that I made some time ago, but then I decided to go with something much refined.

This will begin from A5 =IF(G5="","",IF(A4="",1,A4+1))
A4 is blank.
 
Upvote 0
I will have to try to download your file later. I cannot do it from my present location.
 
Upvote 0
I will have to try to download your file later. I cannot do it from my present location.
No point, it's just got the two formula
Excel Formula:
=IF(OR(M1="(All)",M1=""),"",OFFSET(A1,-1,0)+1)
=AlphaNumericOnly(C2)
In A1 & A2 & nothing else.
 
Upvote 0
@omairhe
Are you actually using the OFFSET function in the "problem" workbooks?
 
Upvote 0
No point, it's just got the two formula
Excel Formula:
=IF(OR(M1="(All)",M1=""),"",OFFSET(A1,-1,0)+1)
=AlphaNumericOnly(C2)
In A1 & A2 & nothing else.
I need a feedback as it currently seems that by pasting these two formulas in A1 and A2 and also the corresponding function of A2 in a workbook module, the problem should 100% be recreated as far as I'm concerned. Is it not the case with you guys? Like you said it yourself, the workbook is entirely empty except for those two formulas and the function that goes with the A2. This is enough to give that save prompt at startup, even though no changes are being made to the file.
 
Upvote 0
If I set up a sheet as you described here:
No I created this file just to demo the save prompt problem.
My original file will not begin from A1 but A5. For instance A5 to A10 then row 11 is all blank then A12 to A20 and so on and so forth.

I want the serial numbering to reset after each blank row. for instnce at A12 begin from 1 again.
I am posting here one that I made some time ago, but then I decided to go with something much refined.

This will begin from A5 =IF(G5="","",IF(A4="",1,A4+1))
A4 is blank.
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
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,979
Members
448,934
Latest member
audette89

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