Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default macro definition

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default macro definition

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
--
HTH...

Jim Thomlinson


"andresg1975" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default macro definition

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.

--
Regards,
Tom Ogilvy


"andresg1975" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default macro definition

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
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"andresg1975" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default macro definition

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

Jim Thomlinson


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"andresg1975" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro definition help andresg1975 Excel Programming 1 March 29th 07 05:54 PM
Macro to Uncheck Save Query Definition NYbills Excel Programming 1 July 28th 06 06:51 PM
Range Definition in Macro ? Baapi Excel Programming 1 September 23rd 05 12:08 AM
Syntax problem in defining OnAction macro definition held in Add-in! Charles Jordan Excel Programming 4 March 5th 05 06:35 AM
Remove Query Definition with Macro or VBA Paul Simpson Excel Programming 2 January 6th 05 11:20 AM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"