In VBA, each workbook has a collection of worksheets. With a worksheet, it either exists in the workbook or it doesn’t. With workbooks you may need to open them, find which folder they are in, check if they are in use and so on. Using Worksheets is more straightforward than using workbooks. However, you will mainly use it to perform some action on one or more cells on the worksheet. You may use it to protect, hide, add, move or copy a worksheet. The most common use of the worksheet in VBA is for accessing its cells. Of all the code your write, 90% will involve one or all of them. The three most important elements of VBA are the Workbook, the Worksheet and Cells. Worksheets.Add after:=Worksheets(Worksheets.Count) Otherwise the active workbook will be used by default.Īccess using worksheet code name(current workbook only)Īccess using worksheet code name(other workbook) You should always specify the workbook when using Worksheets. This is to make the examples clear and easy to read. Worksheets rather than ThisWorkbook.Worksheets, wk.Worksheets etc. Note: I use Worksheets in the table below without specifying the workbook i.e. The following table gives a quick run down to the different worksheet methods.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |