SOLVED
Home

Correct use of Worksheets statement in VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-394287%22%20slang%3D%22en-US%22%3ECorrect%20use%20of%20Worksheets%20statement%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394287%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20function%20where%20I%20am%20seeking%20to%20look%20across%20from%26nbsp%3B%20a%20worksheet%20in%20one%20workbook%20to%20a%20worksheet%20in%20another%20workbook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20a%20name%20reference%20across%20to%20the%20other%20sheet%2C%20the%20name%20is%20Subsidiary_Names_Sheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20then%20use%20that%20name%20in%20the%20call%20to%20my%20function%20within%20the%20CELL%20function%2C%20viz.%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(CELL(%22filename%22%2CSubsidiary_Names_Sheet))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20results%20in%20the%20function%20receiving%20the%20worksheet%20reference%20as%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EE%3A%5COld%20PC%5CFamily_History%20(G)%5CJohnson%20Extended%20Family%20History%5C%5BGenealogical_Service_Users_Tracing_Project_Families.xlsm%5DNames%20in%20Alpha%20Order%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20then%20use%20that%20parameter%20along%20with%20a%20couple%20of%20loop%20counts%2C%20viz%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETest_Surname%20%3D%20Worksheets(fWksht_Srce).Cells(I%2C%20J).Value%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20will%20'convert'%2C%20at%20execution%2C%20for%20example%2C%20into%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETest_Surname%20%3D%20Worksheets(E%3A%5COld%20PC%5CFamily_History%20(G)%5CJohnson%20Extended%20Family%20History%5C%5BGenealogical_Service_Users_Tracing_Project_Families.xlsm%5DNames%20in%20Alpha%20Order).Cells(3%2C%204).Value%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebut%20this%20does%20not%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20parameters%20are%20being%20received%20by%20the%20function%2C%20just%20as%20I%20want%2C%20and%20the%20loop%20counts%20are%20starting%20correctly%2C%20but%20I%20am%20clearly%20not%20using%20precisely%20the%20correct%20syntax%20in%20the%20Worksheets%20statement.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20I%20need%20some%20double%20and%2For%20single%20quotes%20somewhere%3F%26nbsp%3B%20Am%20I%20passing%20the%20wrong%20reference%20type%20in%20my%20CELL%20statement%3F%26nbsp%3B%20Or%20is%20there%20something%20else%20wrong.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20done%20some%20further%20research%20and%20found%20information%20that%20points%20me%20in%26nbsp%3B%20the%20direction%20of%20needing%20to%20declare%20Excel.Workbook%20and%20Excel.Worksheet%20variables%20within%20the%20function%2C%20which%20I%20have%20done%20but%20I%20am%20still%20getting%20a%20subscript%20out%20of%20range%20error%20when%20I%20execute%20the%20statement%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20thanks%20in%20anticipation.%26nbsp%3B%20Ideas%20please.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20for%20completeness%20I%20post%20below%20the%20text%20of%20the%20call%20and%20the%20full%20text%20of%20the%20function%20(as%20now%20updated%20since%20the%20time%20of%20the%20original%20post)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECall%3A%3C%2FP%3E%3CP%3E%3DSubsidiary_Family_to_Main_Family_Index_Number(Z463%2C(CELL(%22contents%22%2CMain_Families_Count))%2C(CELL(%22filename%22%2CSubsidiary_Names_Sheet)))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20Subsidiary_Family_to_Main_Family_Index_Number(Subord_Surname%20As%20String%2C%20Fams_Cnt%20As%20Long%2C%20Worksheet_Source%20As%20String)%20As%20Long%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20fSubord_Surname%20As%20String%3CBR%20%2F%3EDim%20fFams_Cnt%20As%20Long%3CBR%20%2F%3EDim%20fWksht_Srce%20As%20String%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20fExt_Workbook_Name%20As%20String%3CBR%20%2F%3EDim%20fExt_Worksheet_Name%20As%20String%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20fExt_Workbook%20As%20Excel.Workbook%3CBR%20%2F%3EDim%20fExt_Worksheet%20As%20Excel.Worksheet%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20Len_fWksht_Srce%20As%20Long%3CBR%20%2F%3EDim%20Len_fExt_Workbook_Name%20As%20Long%3CBR%20%2F%3EDim%20Len_fExt_Worksheet_Name%20As%20Long%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20Test_Surname%20As%20String%3CBR%20%2F%3EDim%20TSChar%20As%20String%3C%2FP%3E%3CP%3EDim%20I%20As%20Long%3CBR%20%2F%3EDim%20J%20As%20Long%3CBR%20%2F%3EDim%20R%20As%20Long%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EfSubord_Surname%20%3D%20Subord_Surname%3CBR%20%2F%3EfFams_Cnt%20%3D%20Fams_Cnt%3CBR%20%2F%3EfWksht_Srce%20%3D%20Worksheet_Source%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELen_fWksht_Srce%20%3D%20Len(fWksht_Srce)%3CBR%20%2F%3ELen_fExt_Workbook_Name%20%3D%20WorksheetFunction.Find(%22%5D%22%2C%20fWksht_Srce)%3CBR%20%2F%3ELen_fExt_Worksheet_Name%20%3D%20Len_fWksht_Srce%20-%20Len_fExt_Workbook_Name%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EfExt_Workbook_Name%20%3D%20Left(fWksht_Srce%2C%20Len_fExt_Workbook_Name)%3CBR%20%2F%3EfExt_Worksheet_Name%20%3D%20Right(fWksht_Srce%2C%20Len_fExt_Worksheet_Name)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'%20The%20following%20statement%20is%20where%20I%20am%20getting%20the%20subscript%20out%20of%20range%20error%20-%20I%20have%20even%20tried%3C%2FP%3E%3CP%3E'%20to%20do%20the%20statement%20in%20the%20immediate%20window%20(within%20debug)%2C%20but%20using%20literals%2C%20rather%20than%20the%3C%2FP%3E%3CP%3E'%20variable%20name%3B%20I%20still%20get%20the%20same%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet%20fExt_Workbook%20%3D%20Excel.Workbooks(fExt_Workbook_Name)%3CBR%20%2F%3ESet%20fExt_Worksheet%20%3D%20fExt_Workbook.Worksheets(fExt_Worksheet_Name)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ER%20%3D%200%3CBR%20%2F%3EI%20%3D%200%3CBR%20%2F%3EJ%20%3D%200%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20I%20%3D%203%20To%20(fFams_Cnt%20%2B%202)%3CBR%20%2F%3EFor%20J%20%3D%204%20To%2024%3CBR%20%2F%3ETest_Surname%20%3D%20fExt_Worksheet.Cells(I%2C%20J).Value%3CBR%20%2F%3ETSChar%20%3D%20Test_Surname%3CBR%20%2F%3EIf%20Test_Surname%20%3D%20fSubord_Surname%20Then%3CBR%20%2F%3ER%20%3D%20I%3CBR%20%2F%3EGoTo%20Heading_Out%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%20J%3CBR%20%2F%3ENext%20I%3C%2FP%3E%3CP%3EHeading_Out%3A%3C%2FP%3E%3CP%3ESubsidiary_Family_to_Main_Family_Index_Number%20%3D%20R%3C%2FP%3E%3CP%3EEnd%20Function%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-394287%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-399604%22%20slang%3D%22en-US%22%3ERe%3A%20Correct%20use%20of%20Worksheets%20statement%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-399604%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDear%20Peter%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20pointing%20me%20in%20the%20right%20direction.%26nbsp%3B%20I%20eventually%20wrote%20two%20other%20small%20functions%20which%20stripped%20the%20CELL%20return%20value%20down%20to%20just%20the%20workbook%20and%20worksheet%20names%2C%20respectively.%26nbsp%3B%20This%20then%20made%20the%20central%20essence%20of%20the%20function%20work.%26nbsp%3B%20I%20could%20therefore%20remove%20all%20the%20string%20manipulation%20from%20the%20'main'%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPhilip%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394752%22%20slang%3D%22en-US%22%3ERe%3A%20Correct%20use%20of%20Worksheets%20statement%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394752%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F313780%22%20target%3D%22_blank%22%3E%40PMHunt1955%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wonder%20whether%20opening%20the%20target%20workbook%20and%20then%20working%20step%20by%20step%20might%20provide%20a%20starting%20point.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet%20wb%20%3D%20Workbooks(%22Genealogical_Service_Users_Tracing_Project_Families.xlsm%22)%3CBR%20%2F%3ESet%20ws%20%3D%20wb.Worksheets(%22Names%20in%20Alpha%20Order%22)%3CBR%20%2F%3ETest_Surname%20%3D%20ws.Cells(3%2C%204).Value%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESomething%20radically%20different%20might%20be%20to%20ditch%20the%20usual%20sheet%20name%20and%20cell%20address%20approach%20and%20go%20for%20a%20Table%20using%20Power%20Query%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394688%22%20slang%3D%22en-US%22%3ERe%3A%20Correct%20use%20of%20Worksheets%20statement%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394688%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDear%20Jan%3C%2FP%3E%3CP%3EThank%20you%20for%20replying.%3C%2FP%3E%3CP%3EI%20feel%20that%20the%20essence%20of%20my%20problem%20is%20stated%20quite%20clearly%20in%20the%20first%20sentence%20but%20I%20will%20slightly%20reword%20it%2C%20with%20the%20hope%20that%20this%20helps.%3C%2FP%3E%3CP%3EI%20have%20a%20function%20which%20is%20called%20from%20a%20worksheet%20in%20one%20workbook%2C%20where%20the%20function%20needs%20to%20view%2C%20in%20succesion%2C%20within%20a%20couple%20of%20nested%20for-next%20loops%2C%20the%20contents%20of%20a%20series%20of%20cells%20(one%20at%20a%20time)%2C%20which%20are%20located%20in%20a%20worksheet%20in%20another%20workbook.%20Both%20workbooks%20are%20open.%3C%2FP%3E%3CP%3EThe%20following%20statement%20is%20where%20I%20am%20getting%20the%20subscript%20out%20of%20range%20error%20-%20I%20have%20even%20tried%20to%20do%20the%20statement%20in%20the%20immediate%20window%20(within%20debug)%2C%20but%20using%20literals%2C%20rather%20than%20the%20variable%20name%3B%20I%20still%20get%20the%20same%20error.%3CBR%20%2F%3E%3CBR%20%2F%3E%5BCODE%5D%3CBR%20%2F%3ESet%20fExt_Workbook%20%3D%20Excel.Workbooks(fExt_Workbook_Name)%3C%2FP%3E%3CP%3E%5B%2FCODE%5D%3C%2FP%3E%3CP%3EI%20have%20tried%20to%20follow%20the%20guidance%20that%20I%20have%20read%20through%20a%20number%20of%20other%20threads%20on%20a%20few%20different%20Excel%20support%20bulletin%20boards%2C%20which%20have%20discussed%20similar%20situations%2C%20but%20I%20am%20just%20not%20doing%20exactly%20the%20right%20thing%2C%20obviously.%3C%2FP%3E%3CP%3EI%20apologise%20for%20what%20you%20feel%20is%20the%20long%20windedness%20of%20my%20question%3B%20I%20have%2C%20though%2C%20often%20found%20that%20'helpers'%20ask%20to%20see%20the%20full%20code%2C%20so%20that%20is%20why%20it%20is%20there.%3C%2FP%3E%3CP%3EAs%20you%20say%20I%20am%20also%20fairly%20confident%20that%20what%20I%20am%20trying%20to%20achieve%20is%20not%20that%20difficult%20in%20Excel%2C%20but%20I%20have%20just%20got%20the%20syntax%20wrong%20somewhere.%3C%2FP%3E%3CP%3EBest%20regards%3C%2FP%3E%3CP%3EPhilip%3C%2FP%3E%3CP%3EP.%20S.%20I%20used%20to%20be%20a%20mainframe%20%2F%20mini%20programmer%20in%20PL%2F1%2C%20COBOL%20and%20dBase%2C%20so%20that%20is%20why%20I%20often%20try%20to%20do%20more%20tricky%20things%2C%20eh.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-394630%22%20slang%3D%22en-US%22%3ERe%3A%20Correct%20use%20of%20Worksheets%20statement%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-394630%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3CBR%20%2F%3EYour%20question%20is%20quite%20difficult%20to%20read%20through%20and%20hence%20to%20answer.%20Can%20you%20try%20to%20reduce%20the%20question%20to%20a%20slightly%20simpler%20problem%20please%3F%20I%20am%20confident%20what%20you%20are%20trying%20to%20achieve%20isn%3Bt%20that%20hard%20in%20VBA%2C%20but%20the%20complexity%20of%20the%20question%20makes%20it%20very%20hard%20to%20understand%20the%20setup.%3C%2FP%3E%3C%2FLINGO-BODY%3E
PMHunt1955
Contributor

I have a function where I am seeking to look across from  a worksheet in one workbook to a worksheet in another workbook.

 

I have created a name reference across to the other sheet, the name is Subsidiary_Names_Sheet.

 

I then use that name in the call to my function within the CELL function, viz. -

 

(CELL("filename",Subsidiary_Names_Sheet))

 

This results in the function receiving the worksheet reference as -

 

E:\Old PC\Family_History (G)\Johnson Extended Family History\[Genealogical_Service_Users_Tracing_Project_Families.xlsm]Names in Alpha Order

 

I then use that parameter along with a couple of loop counts, viz -

 

Test_Surname = Worksheets(fWksht_Srce).Cells(I, J).Value

 

This will 'convert', at execution, for example, into

 

Test_Surname = Worksheets(E:\Old PC\Family_History (G)\Johnson Extended Family History\[Genealogical_Service_Users_Tracing_Project_Families.xlsm]Names in Alpha Order).Cells(3, 4).Value

 

but this does not work.

 

The parameters are being received by the function, just as I want, and the loop counts are starting correctly, but I am clearly not using precisely the correct syntax in the Worksheets statement.

 

Do I need some double and/or single quotes somewhere?  Am I passing the wrong reference type in my CELL statement?  Or is there something else wrong.

 

I have done some further research and found information that points me in  the direction of needing to declare Excel.Workbook and Excel.Worksheet variables within the function, which I have done but I am still getting a subscript out of range error when I execute the statement -

 

With thanks in anticipation.  Ideas please.

 

Just for completeness I post below the text of the call and the full text of the function (as now updated since the time of the original post)

 

Call:

=Subsidiary_Family_to_Main_Family_Index_Number(Z463,(CELL("contents",Main_Families_Count)),(CELL("filename",Subsidiary_Names_Sheet)))

 

Function:

 

Function Subsidiary_Family_to_Main_Family_Index_Number(Subord_Surname As String, Fams_Cnt As Long, Worksheet_Source As String) As Long

 

Dim fSubord_Surname As String
Dim fFams_Cnt As Long
Dim fWksht_Srce As String

 

Dim fExt_Workbook_Name As String
Dim fExt_Worksheet_Name As String

 

Dim fExt_Workbook As Excel.Workbook
Dim fExt_Worksheet As Excel.Worksheet

 

Dim Len_fWksht_Srce As Long
Dim Len_fExt_Workbook_Name As Long
Dim Len_fExt_Worksheet_Name As Long

 

Dim Test_Surname As String
Dim TSChar As String

Dim I As Long
Dim J As Long
Dim R As Long

 

fSubord_Surname = Subord_Surname
fFams_Cnt = Fams_Cnt
fWksht_Srce = Worksheet_Source

 

Len_fWksht_Srce = Len(fWksht_Srce)
Len_fExt_Workbook_Name = WorksheetFunction.Find("]", fWksht_Srce)
Len_fExt_Worksheet_Name = Len_fWksht_Srce - Len_fExt_Workbook_Name

 

fExt_Workbook_Name = Left(fWksht_Srce, Len_fExt_Workbook_Name)
fExt_Worksheet_Name = Right(fWksht_Srce, Len_fExt_Worksheet_Name)

 

' The following statement is where I am getting the subscript out of range error - I have even tried

' to do the statement in the immediate window (within debug), but using literals, rather than the

' variable name; I still get the same error.

 

Set fExt_Workbook = Excel.Workbooks(fExt_Workbook_Name)
Set fExt_Worksheet = fExt_Workbook.Worksheets(fExt_Worksheet_Name)

 

R = 0
I = 0
J = 0

 

For I = 3 To (fFams_Cnt + 2)
For J = 4 To 24
Test_Surname = fExt_Worksheet.Cells(I, J).Value
TSChar = Test_Surname
If Test_Surname = fSubord_Surname Then
R = I
GoTo Heading_Out
End If
Next J
Next I

Heading_Out:

Subsidiary_Family_to_Main_Family_Index_Number = R

End Function

4 Replies

Hi,
Your question is quite difficult to read through and hence to answer. Can you try to reduce the question to a slightly simpler problem please? I am confident what you are trying to achieve isn;t that hard in VBA, but the complexity of the question makes it very hard to understand the setup.

@Jan Karel Pieterse 

Dear Jan

Thank you for replying.

I feel that the essence of my problem is stated quite clearly in the first sentence but I will slightly reword it, with the hope that this helps.

I have a function which is called from a worksheet in one workbook, where the function needs to view, in succesion, within a couple of nested for-next loops, the contents of a series of cells (one at a time), which are located in a worksheet in another workbook. Both workbooks are open.

The following statement is where I am getting the subscript out of range error - I have even tried to do the statement in the immediate window (within debug), but using literals, rather than the variable name; I still get the same error.

[CODE]
Set fExt_Workbook = Excel.Workbooks(fExt_Workbook_Name)

[/CODE]

I have tried to follow the guidance that I have read through a number of other threads on a few different Excel support bulletin boards, which have discussed similar situations, but I am just not doing exactly the right thing, obviously.

I apologise for what you feel is the long windedness of my question; I have, though, often found that 'helpers' ask to see the full code, so that is why it is there.

As you say I am also fairly confident that what I am trying to achieve is not that difficult in Excel, but I have just got the syntax wrong somewhere.

Best regards

Philip

P. S. I used to be a mainframe / mini programmer in PL/1, COBOL and dBase, so that is why I often try to do more tricky things, eh.

Solution

@PMHunt1955 

I wonder whether opening the target workbook and then working step by step might provide a starting point.

 

Set wb = Workbooks("Genealogical_Service_Users_Tracing_Project_Families.xlsm")
Set ws = wb.Worksheets("Names in Alpha Order")
Test_Surname = ws.Cells(3, 4).Value

 

Something radically different might be to ditch the usual sheet name and cell address approach and go for a Table using Power Query?

@Peter Bartholomew 

 

Dear Peter

 

Thank you for pointing me in the right direction.  I eventually wrote two other small functions which stripped the CELL return value down to just the workbook and worksheet names, respectively.  This then made the central essence of the function work.  I could therefore remove all the string manipulation from the 'main' function.

 

Best

 

Philip

 

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
16 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies