Function Spreadsheet check not working

ReinhardtSteyn

New Member
Joined
Mar 22, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Good Day

I created a test spreadsheet in order to test coding to determine if spreadsheet name exists. The following coding was used:
VBA Code:
'Inputs:
'WhatSheet - String Name of Sheet (ex "Sheet1")
' WhatRange (Optional, Default = "A1") - String Name of Range (ex "A1")
Function RangeExists(WhatSheet As String, Optional ByVal WhatRange As String = "A1") As Boolean
    'WhatSheet = ActiveWorkbook.Sheets("SHEET5").Range("a" & i1)
    Dim test As Range
    On Error Resume Next
    Set test = ActiveWorkbook.Sheets(WhatSheet).Range(WhatRange)
    RangeExists = Err.Number = 0
    On Error GoTo 0
End Function

Sub CheckSheetexists()
Dim i1 As Integer
Dim WhatSheet As String

For i1 = 7 To 12
WhatSheet = ActiveWorkbook.Sheets("SHEET5").Range("E" & i1)
ActiveWorkbook.Sheets("SHEET5").Range("F" & i1).Formula = "=RangeExists(E" & i1 & ")"


Next i1

End Sub

Following results was returned which is correct.

1616402801692.png


When I apply this same coding to the spreadsheet intendent to following results are returned:

1616402916855.png


I'm not sure why this is happening. When I use the F8 in the VBA to perform the run by line to check the coding, I noted that the function is not triggered. The function is perfectly triggered in my test spreadsheet.

The intendent spreadsheet is saved in ".xlsb" format. Even tried saving the spreadsheet in a micro enabled format, but still the function is not triggered.

Help will be much appreciated
 
Last edited by a moderator:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If I remember correctly, you need to include the filename in the formula, e.g.
Excel Formula:
=[Personal.xlsb]!RangeExists(A1)
 
Upvote 0
Did you put the function code in the workbook where it is not working? If so, where (i.e. in which module)? It needs to be in a normal module. If it's not in that workbook, then as Jason said, you need to include the name of the workbook that does have the code in it.
 
Upvote 0
Solution
Thank you so much for the help.

Just to give you guys some idea of what I'm doing. I created a macro to import employee information from another workbook, but required the function to work in this other workbook. Did not realize I had to add a separate module in the other workbook. I created a new module in the separate workbook and added the function coding in that workbook. Works perfectly now.

I still new at macro so still learning how macros work.
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,320
Members
448,887
Latest member
AirOliver

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