Hi there,
I got this code from the website, and I am having trouble interpreting what the "step - 1" represents. I have seen this construct frequently these days, but I don't understand how it works.
The code is supposed to highlight duplicates in color red according its original description.
ThanksSub DupsRed() Application.ScreenUpdating = False Rng = Selection.Rows.Count For i = Rng To 1 Step -1 myCheck = ActiveCell ActiveCell.Offset(1, 0).Select For j = 1 To i If ActiveCell = myCheck Then Selection.Font.Bold = True Selection.Font.ColorIndex = 3 End If ActiveCell.Offset(1, 0).Select Next j ActiveCell.Offset(-i, 0).Select Next i Application.ScreenUpdating = True End Sub
Step - 1 literally means it will work through a loop count backwards one at a time.
I'm not sure that it's necessary in this case.
Dom
"May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."
Use code tags when posting your VBA code: [code] Your code here [/code]
Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.
thank you Dom
Just to add a bit more info:
The Step n part is optional - if omitted it defaults to Step 1.
The n part can be any number, positive or negative - it does not have to be an integer.
Some demonstrations
I would generally advise not using Step 0 though...Sub demo_step_loops() Dim n As Long Dim d As Double Dim strTemp As String For n = 1 To 10 Step 1 strTemp = strTemp & vbLf & n Next n MsgBox Mid$(strTemp, 2) strTemp = "" For n = 10 To 1 Step -2 strTemp = strTemp & vbLf & n Next n MsgBox Mid$(strTemp, 2) strTemp = "" For d = 10 To 1 Step -0.5 strTemp = strTemp & vbLf & d Next d MsgBox Mid$(strTemp, 2) End Sub![]()
Good luck.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks