macro definition

A

andresg1975

can someone explain to me the function of this macro. Thanks for your help

Sub INSONEEVERYTWOROWS()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "N").End(xlUp).Row
iLastRow = iLastRow - (iLastRow Mod 2 = 0)
For i = iLastRow To 2 Step -2
Rows(i).Resize(1).Insert
Next i

End Sub
 
J

Jim Thomlinson

I have commented the Code for you...

Sub InsOneEveryTwoRows()
Dim iLastRow As Long 'Variable to hold row number of last cell
Dim i As Long 'Variable to move up through the rows

iLastRow = Cells(Rows.Count, "N").End(xlUp).Row 'Get last row # in
Column N
iLastRow = iLastRow - (iLastRow Mod 2 = 0) 'Make last row an Even Number
For i = iLastRow To 2 Step -2 'Step up from the last row to the second row
'2 rows at a time
Rows(i).Resize(1).Insert 'at each step insert a row
Next i 'Step up 2 rows

End Sub
 
T

Tom Ogilvy

it finds the lastrow with data in column "N"

if it is an odd row, it starts there. If it is an even row, it adds 1 to
the row and starts there.

It then steps back to row 2 looking only at the odd rows.

For each odd row, it inserts a new row. It goes from high numbered row to
low numbered row to avoid having the macro adversely affected by changes it
has made.
 
J

Jim Thomlinson

I believe it subtracts to the previous even row number

iLastRow = iLastRow - (iLastRow Mod 2 = 0)

For example
10-10 Mod 2 = 10
11-11 Mod 2 = 10
 
J

Jim Thomlinson

Forget this response... you are correct.
(10 Mod 2 = 0) -> True -> True = 1
Now I get it... Just an odd way of doing it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Find Copy Paste Special 3
Dynamic Array not response 5
Exclude rows with result 1 1
Input box default = last input 6
Adding Rows 2
Is it a duplicate row? 7
Copy lines with specific value 3
Excel 2007 1

Top