This should be easy. I would like to reduce the usage of the code worksheets("Sheet1").activate
as it is cumbersome and faulty oftentimes, however all the attempts I have tried out they do not work. So far I have used the set worksheet
option and with worksheet
option but unless I am strictly on the worksheet sheet 1 on Excel , the code does not execute.
I have tried some of the options listed in this link but none of them worked: How to avoid using Select in Excel VBA. I am really starting to think that I need to use activate all the time.
For example, a code like:
Sub test()
Dim Cols As integer
Cols = Worksheets("Sheet1").Range(Cells(1, 1), Cells(1, 1).End(xlToRight)).Count
End sub
I would expect that this code execute even if I am not situated on Sheet1 since I have specifically defined the worksheet in which it must be executed. However, unless I am on that worksheet, the code does not work. As background information, I run most of my codes under subroutines in the modules section of VBA.