Folks
I am new to VBA and I am learning as I go along mainly thanks to your generosity (I posted two queries in the last couple of weeks and got instant and practical response to both. Thanks!) and Mr Google’s functionality
The question today if I may relates to the way sheets(“sheetname”).select work or in my case doesn’t work in user defined function (It works fine in a Sub macro)
I have a workbook with 3 sheets called summary, data and Test
My function is as follows :
Function test()
Sheets("Summary").Select
NM1 = ActiveSheet.Name
‘ do some work
Sheets("Data").Select 'Navigate to data
NM2 = ActiveSheet.Name
‘ do some work
End function
When I starti am positioned on the test work sheet
When I convert this function to a sub and run the macro I can see that it work ie nm1 & nm2 show “summary” and “Data” respectively but when I executed it as a function I find that nm1 and nm2 are both set to “test”
Why is it so
I am new to VBA and I am learning as I go along mainly thanks to your generosity (I posted two queries in the last couple of weeks and got instant and practical response to both. Thanks!) and Mr Google’s functionality
The question today if I may relates to the way sheets(“sheetname”).select work or in my case doesn’t work in user defined function (It works fine in a Sub macro)
I have a workbook with 3 sheets called summary, data and Test
My function is as follows :
Function test()
Sheets("Summary").Select
NM1 = ActiveSheet.Name
‘ do some work
Sheets("Data").Select 'Navigate to data
NM2 = ActiveSheet.Name
‘ do some work
End function
When I starti am positioned on the test work sheet
When I convert this function to a sub and run the macro I can see that it work ie nm1 & nm2 show “summary” and “Data” respectively but when I executed it as a function I find that nm1 and nm2 are both set to “test”
Why is it so