![]() ![]() Visual Basic Editor is opened now and by default, a subroutine is already created for the command button. ![]() Step 6: Now we need to declare 3 variables. And the 3 rd variable will be as Long to count the numbers stored in each row.ĭim A As Integer Dim Count As Integer Dim LRow As Long End Sub Declare the first variable where we will store the numbers and second variable by which we will use the counter as integers as shown below. LRow = Range("A1").CurrentRegion.End(xlDown).Row From here we will be selecting the cells till it has the numbers.ĭim A As Integer Dim Count As Integer Dim LRow As Long Step 7: Now we will select the first cell of the sheet which is A1 as our range. Step 8: Now we will open and write the condition in For loop for, if the cell has the value greater than 10 then cell font color will be changed to Yellow and for the value less than 10, the cell font color will be changed to Blue with the color indices 44 and 55 respectively. Step 9: Now to see the output of the values from cell A1 till the end, we will select the cells as discussed above by the below code. Step 10: Now run the code by pressing the button. We will see, the cells containing the numbers less than 10 are highlighted in blue color. And the one greater than 10 is highlighted in Yellow. In this example, we will use VBA Counter to measure the time by which we can measure the take we do. Suppose, if we need to measure the time required to complete any task, then the process we will be seeing here is the best to implement. Step 1: Create the 2 tabs of any shape from Insert menu Shapes options as shown below. We are selecting Rectangle: Rounder Corners. Step 2: Create 2 buttons and name them as Start and Reset by which we will start the timer and clear the time. Step 3: Now go to VBA and open a Module from the Insert menu. Step 4: In that write the subcategory of Start timer as shown below. ![]() Step 5: Consider a word for the Next row such as NextRow where we will select the worksheet in which we want to implement the code. NextRow = ThisWorkbook.Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1 And here we will count the Rows from +1 cell which is cell A2 till we have cursor file the value. Step 6: Now to get into the next row we will use vertex format where 1 in the bracket is for Y-axis. Step 7: Write the code for Reset below the same Start code. Lastrow = ThisWorkbook.Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row Step 8: Now for reset, we will keep the same code as Start but the keyword will get changed to LastRow and we remove +1 just so we don’t have to get into another row. Step 9: Now to clear the data in column A’s last cell to the first cell first select the range of cells with function ClearContents. Step 10: Right-click on the Start tab and select the Assign Macro option. Step 11: Select the Start sub coding which we did above. Step 12: Same do for the Reset button as well. Assign the Reset sub-code to the Reset button and click on Ok and exit from the design mode to execute the code. Step 13: Now click the Start button first. Step 14: Now again click on the Start button 2-3 times to get multiple time-lapse. We will see, there is a gap of a few seconds in each iteration. Step 15: Now after that, we will test the Reset button. We will see, the data is now cleared and ready for another time count laps.It is very easy to implement the time laps counter as we saw in example-2.VBA Counter has many implementation types, this is not just limited to the examples we have seen.It is always better to assign the code for any button when we have performed 2 or more types of code in one process.Save the macro in Macro enable excel file format so that we would not lose our code.We can also create a live time counter where we can see the countdown of time or watch time in real.Exit design mode once code assignment and execution are done from the Developer tab. Here we discuss how to create VBA Counter in Excel using VBA code along with practical examples and downloadable excel template.2023.03.03 09:35 PatternTrader2 $LDNXF Trading Ideas Awaiting Buy signal. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |