Download the spreadsheet accompanying this tutorial (below or in the side-menu) and you can follow the examples presented here. Remember, arrays in VBA can be confusing, BUT, they will save you a lot of time once you get comfortable using them. The main thing is to try and make everything as intuitive as possible so that you still understand what your Macro VBA is doing when you look at the code a year later.Īs for the rest of this macro, it functions the same as in the previous two examples. You could basically have the index numbers be any range (5 to 10), (10 to 20), (50 to 100) or whatever you need. In this case, the very first item red will be stored at index level 1 and nothing will be stored at index level 0. Werken met VBA-macros in Excel voor het web Webversie van ExcelMeer. This is much more intuitive than having it start at 0 and end at 2 in order to store three items, as it was in the previous example. What this says is that the myarray array variable should have its index number start at 1 and end at 3. You can just as easily store text with numbers in the same array variable. These two arrays, one to show you how to store text values and the other to show you how to store numbers are almost the same except that text must be surrounded with double quotation marks. Notice that the variables are not even declared at the top of the Macro (though that is good practice, it is not required here).ĭownload the accompany Excel spreadsheet from the side-menu or below this tutorial in order to test this and the following macros. These arrays are simply variables which use the Array() function in order to be turned into arrays. The array variables are myarray and mysecondarray. This is the simplest way to create an array variable in VBA and Macros for Excel. MsgBox myarray(0) & " " & mysecondarray(2)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |