Use vbBlue or vbGreen type to define the color. Step 5: Now to change the interior color of blank cells, use Interior.Color and choose the color by which we want to highlight the blank cells. Step 4: Now select the Range of numbers using defined variable A and choose xlCellTypeBlanks to select the blank cells only. Step 3: Now set this variable as Selection Step 2: Define a variable using DIM as Range, as we are selecting the exiting number range. Step 1: Open a Module, write the subprocedure as shown below. For this, we have used the same number as we did in the above example but we have deleted some of the cells to get the output.
#Excel vba examples code how to
In this example, we will see how to change the color of blank cells from the selected ranges. We will see the same number starting from 1 to 10 got printed in column B as well from cell B1 to B10.
#Excel vba examples code code
Step 8: Again run the complete code by pressing the F8 key or by clicking on the Play button. Or else add another line of code as shown below. Step 7: What if we try to add these numbers in the second column? Change the column vertex from 1 to 2. We will see, the numbers are generated from cell A1 to A10 starting from 1 to 10. Step 6: Now run the code by pressing the F8 key or by clicking on the Play button. As we chose 1 so we expect to see the numbers starting from cell A1.
Here, second position vertex in Cell shows Column number.
Step 5: Now fix the cell position with variable A.
Step 4: Now select the cell range from where we want to see number till the last in For syntax. Step 3: Again open a For-Next loop as shown below. As we are using the numbers to Integer data type should be used. Step 2: Consider a variable using DIM as Integer. Step 1: Open a Module and write the subprocedure. This process is quite the same as we have seen in example-2. In this example, we will learn how to print the numbers. We will see, as we had 3 sheets, all named default so their name got printed from cell A1 to below till the number of Sheets we have. Step 5: Now we assign the variable A with cell Value to see the Sheet name as shown below. Here as we don’t have any header reference so we can start from cell 1.ĭim A As Integer For A = 1 To Sheets.Count Step 4: Select the position of cell from where we want to see the Sheet names. Step 3: Open a For-Next loop as shown below. We can choose the name variable as we did in example-1. Step 1: Open a Module and write the subprocedure as shown below. Now in this example, we will see another example where we will use the For-Next loop to print the sheet names. ( Note: Press Ctrl+ G to open immediate window) Step 7: This could have been done using Debug Print function as well, whose values are seen in Immediate Window. We will see the message box with the value 100 in it. Step 6: Run the code by pressing the F8 key or by clicking on the Play Button located below the menu bar. Step 5: Now we will use the message box to print the value stored in Variable A.