Sub Onadd()
'Dim - Declares variables and (optionally) their data types. rng in this case is just what the user decided to name that as a range.
'Range - is like a cell selection from a number of selected cells like A3:A8 however with Range its declared as a method not as a specific set of cells
Dim rng As Range
'Integer - A data type that holds integer variables stored as 2-byte whole numbers in the range -32,768 to 32,767. The Integer data type is also used to represent enumerated values. The percent sign (%) type-declaration character represents an Integer in Visual Basic.
Dim intRow As Integer
'With - Allows a shorthand way of accessing multiple properties for an object. Like this With Range selected do the next set of codes writen in that range specified in this case its "Number".
With Range("Number")
'this is setting up rng to be the last row number
Set rng = .Cells(Rows.Count, 1).End(xlUp)
'setting up intRow to = 1 since they setup intRow to be a number earlier in the macro
intRow = 1
'Do - this is a function that will do the code below it and Until is the a criteria that has to be met in order for the code to stop. As an entire line its saying do this until introw or 1 is greater than rng.row or last row. Do this from row 1 until the last row
Do Until intRow > rng.Row
'If is another function that calls one instance of code to take place if a condition is met. This code below seems to add +1 to intRow if the condition is met and then again +1 after even if the condition it met or not. So in some cases it will go up +1 if the condition is not met and when the condition is met it will go up +2 until the last row is reached. However in this case it will skip some of the rows and if this intended function is intended for every row then this code is broken technically. At least i think it is. I could be wrong.
If IsNumeric(.Cells(intRow)) And .Cells(intRow).Value > 0 Then
intRow = intRow + 1
Rows(intRow & ":" & intRow + .Cells(intRow - 1).Value - 1).Insert
.Cells(intRow) = 0
intRow = intRow + .Cells(intRow - 1).Value - 1
End If
intRow = intRow + 1
'loop- is the same as end sub is for sub (). It is the end of the function Do so that the code will loop through once the end of the code is reached until condition of the Do is met then it will go past the Do.
Loop
'End with - is the same as end sub is for Sub (). It is the end of the function If so that the code will know the ending of of the function. On the If fuction you can also add in Else. If x then do this Else do this if condition is not met then End if. So that the code knows where to end or jump to to avoid running a line of code that is not necessary or intended to run.
End With
End Sub
I hope that helps. I am not necessarily the best person to answer however I believe I have enough knowledge to explain it about 90% of it.
Bookmarks