
Excel vba on tablet how to#
Understanding how to refer to worksheets would help you write better code, especially when you’re using loops in your VBA code. There are many different ways you can use to refer to a worksheet in VBA.

In this tutorial, I will be using the ‘Worksheets’ collection only. So if you have to refer to worksheets only, use the ‘Worksheets’ collection, and if you have to refer to all sheets (including chart sheets), the use the ‘Sheets’ collection. Now with this distinction, I recommend being as specific as possible when writing a VBA code.

If you have a workbook that only has worksheets and no chart sheets, then ‘Worksheets’ and ‘Sheets’ collection is the same.īut when you have one or more chart sheets, the ‘Sheets’ collection would be bigger than the ‘Worksheets’ collection In the above example, it would have four elements – 3 Worksheets + 1 Chart sheet.

If > 1 Then 'Only process if the user touches a single cell On Error Resume Next 'Code can error if User selects entire worksheet Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Excel vba on tablet code#
The code only counts the touches to set the color and not to reset to the default but you will get the idea of how to performįor information of others the code is below.ĭim k As Long 'Place this line at top of module before any subsĭim rngToTouch As Range 'Place this line at top of module before any subsĭim arrSelectedCells() As Variant 'Place this line at top of module before any subs You will see that I have included a button to "Reset" the worksheet with default interior color and also reset the count of touches. To see the code, right click the worksheet tab name and select View code. The code is Event code in the worksheets module.
Excel vba on tablet download#
Download from the following link and unzip and test if it is doing what you require. I have uploaded an example workbook as a zipped file to OneDrive.
