![]() ![]() These methods will get data from the currently selected cell within the worksheet.Įither type Selection or type ActiveCell. Method 3 - Use the Location of the Currently Selected Cell I won't show you how to reference a range using this method here because it can get confusing quickly, but a later tutorial will explain it. To reference cell B5, we would input this: Cells(5,2) because B is column 2 and 5 is row 5. The column number starts with column A at 1 and increases by one for each column to the right rows work the same way but going down. To select cell A1, we would do this: Cells(1,1)Ĭells(1,1) means cell A1 because A is the first column and 1 is the first row. This is more complex and less intuitive compared with the last method but it is very important to learn it because you will, very soon, have to use this method to do more complex but very useful operations in macros. Row_number is the row number of the desired cell and column_number is the column number of the desired cell. You can also select a range like this (more on this in a later tutorial): Range("A1:C5") Method 2 - Know Location of the Cell (More Complex Method) If you wanted to reference cell B5, you would type: Range("B5") Make sure to include double quotation marks around the range reference. This is the easiest way to input the location of a cell because it's easy to read and input, you just type the location of the desired cell within Range() and that's it. Method 1 - Know Location of the Cell (Easiest Method)Ĭell_reference is simply the location of the cell. This tutorial will keep it simple and show you three ways to reference a cell, two of them will be when you know the location of the cell and the third will be the cell that the user selects. This can be the hardest part because we don't always know where the desired cell will be located. Sections:įor all who may be impatient or not need a full explanation, here is the final code with the methods for getting data from a cell: Sub get_data() There are two steps required to do this: reference a cell that contains the data that you want and get that data. One of the most important things with macros is getting information from the user, and the most often used method is to get it from a cell in the worksheet. Here, you'll learn how to get information from the Excel worksheet into a macro so you can do something with it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |