VBA Excel Loop Through Entire Columns ( One Column Multiple Rows )
'declare a variable called i of type Long.
Dim i As Long
'Loop through entire Rows
'enters the value 100 into the cell at the intersection of row 1 and column 1 (A) until the cell at the intersection of the last rows of the Excel worksheets and column 1 (A).
For i = 1 To Rows.Count
Cells(i, 1).Value = 100
Cells(i, 1).Font.Bold = True
Next i
Note:
- worksheets can have up to 1,048,576 rows in Excel 2007 or later. No matter what version you are using, the code line above loops through all rows. Warning!: It might hang up you computer, if you have too much data.
- One/1 in Cells(i, 1) can change to column name, example: Cells(i, "A")
VBA Excel Loop Through Entire Columns Based On Certain Conditions
Next, we color all values that are lower than the value entered into cell D2. Empty cells are ignored. Add the following code lines to the loop.
'declare a variable called i of type Long.
Dim i As Long
'Loop through entire Rows
For i = 1 To Rows.Count
If Cells(i, 1).Value < Range("D2").Value And Not IsEmpty(Cells(i, 1).Value) Then
Cells(i, 1).Font.Color = vbRed
End If
Next i
Warning!
When you run a macro, you can’t undo the changes a macro makes. The best option is saving the copy workbook file before running the macro.
Bibliography:
https://www.excel-easy.com/
https://courses.lumenlearning.com/
Tidak ada komentar:
Posting Komentar