Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default adding some rows in the middle of adding some other rows

This macro does half of what I want it to do. I need it also to add the same
number of rows as on the insert line only this time in the middle of the
service group. Since it already added half of the rows at the end of the
first service group
how do I get it to go to the middle of the service group add the same number
of rows and not get out of step for the next service group?

tia,


Public Sub n2m4()

'adds new rows for connections to VOD sheet
' default total rows to add 40

Const ServiceGroupColumn As String = "$H"
Const FirstDataRow As Integer = 12


Dim iRow As Long
Dim rowsToAdd As Integer
Dim LastRow As Long
Dim i As Integer
Dim rng As Range
Dim SvcGrpNum As Long
'Dim SvcGrp As Long

SvcGrpNum = InputBox("Please input the the total number of Service Group
connections from the DNP", "Service Group Number", 40)


With ActiveWorkbook.Worksheets("VOD")
LastRow = .Cells(.Rows.count, ServiceGroupColumn).End(xlUp).Row

i = 1

For iRow = LastRow To FirstDataRow Step -1

i = i + 1
If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1,
ServiceGroupColumn).Value Then
Else

' If ((SvcGrpNum - i) / 2) And 1 Then
' SvcGrp = .Cells(iRow, ServiceGroupColumn).Value
' MsgBox ("Service Group" & " " & SvcGrp & " " & "has an odd
number of rows. Please add a row and start over.")
' Else

rowsToAdd = (SvcGrpNum - i) / 2


.Cells(iRow, ServiceGroupColumn).Resize(rowsToAdd).EntireRow.In sert



i = 1
End If
' End If

Next iRow

End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default adding some rows in the middle of adding some other rows

You might need to put up a sample of your data base again so folks will know
what you mean by service group. What you are trying to do is a little
tricky, since the quantiy of rows per service group vary so widely. If they
were all the same, It would be a pretty simple code.

"Janis" wrote:

This macro does half of what I want it to do. I need it also to add the same
number of rows as on the insert line only this time in the middle of the
service group. Since it already added half of the rows at the end of the
first service group
how do I get it to go to the middle of the service group add the same number
of rows and not get out of step for the next service group?

tia,


Public Sub n2m4()

'adds new rows for connections to VOD sheet
' default total rows to add 40

Const ServiceGroupColumn As String = "$H"
Const FirstDataRow As Integer = 12


Dim iRow As Long
Dim rowsToAdd As Integer
Dim LastRow As Long
Dim i As Integer
Dim rng As Range
Dim SvcGrpNum As Long
'Dim SvcGrp As Long

SvcGrpNum = InputBox("Please input the the total number of Service Group
connections from the DNP", "Service Group Number", 40)


With ActiveWorkbook.Worksheets("VOD")
LastRow = .Cells(.Rows.count, ServiceGroupColumn).End(xlUp).Row

i = 1

For iRow = LastRow To FirstDataRow Step -1

i = i + 1
If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1,
ServiceGroupColumn).Value Then
Else

' If ((SvcGrpNum - i) / 2) And 1 Then
' SvcGrp = .Cells(iRow, ServiceGroupColumn).Value
' MsgBox ("Service Group" & " " & SvcGrp & " " & "has an odd
number of rows. Please add a row and start over.")
' Else

rowsToAdd = (SvcGrpNum - i) / 2


.Cells(iRow, ServiceGroupColumn).Resize(rowsToAdd).EntireRow.In sert



i = 1
End If
' End If

Next iRow

End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default adding some rows in the middle of adding some other rows

sample of my database? this is a spreadsheet. I can give you the header
rows if you want.

The logic of why this works escapes me. It is a hack. It does what I want
for the default number of 40. It is really tricky for me at least. I tried
to backup up to the rows I entered and then add half the amount again. very
hard.

It is connections for servers and they go in pairs. we are adding new
connections half after each service group.

tia,

Const ServiceGroupColumn As String = "$H"
Const FirstDataRow As Integer = 12


Dim iRow As Long
Dim rowsToAdd As Integer
Dim LastRow As Long
Dim i As Integer
Dim rng As Range
Dim SvcGrpNum As Long
'Dim SvcGrp As Long

SvcGrpNum = InputBox("Please input the the total number of Service Group
connections from the DNP", "Service Group Number", 40)


With ActiveWorkbook.Worksheets("VOD")
LastRow = .Cells(.Rows.count, ServiceGroupColumn).End(xlUp).Row

i = 1

For iRow = LastRow To FirstDataRow Step -1

i = i + 1
If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1,
ServiceGroupColumn).Value Then
Else

' If ((SvcGrpNum - i) / 2) And 1 Then
' SvcGrp = .Cells(iRow, ServiceGroupColumn).Value
' MsgBox ("Service Group" & " " & SvcGrp & " " & "has an odd
number of rows. Please add a row and start over.")
' Else

rowsToAdd = (SvcGrpNum - i) / 2


.Cells(iRow, ServiceGroupColumn).Resize(rowsToAdd /
2).EntireRow.Insert
Set rng = .Cells(iRow, ServiceGroupColumn)

rng.Offset(-8, 0).Resize(rowsToAdd).EntireRow.Insert

i = 1
End If
' End If

Next iRow

"JLGWhiz" wrote:

You might need to put up a sample of your data base again so folks will know
what you mean by service group. What you are trying to do is a little
tricky, since the quantiy of rows per service group vary so widely. If they
were all the same, It would be a pretty simple code.

"Janis" wrote:

This macro does half of what I want it to do. I need it also to add the same
number of rows as on the insert line only this time in the middle of the
service group. Since it already added half of the rows at the end of the
first service group
how do I get it to go to the middle of the service group add the same number
of rows and not get out of step for the next service group?

tia,


Public Sub n2m4()

'adds new rows for connections to VOD sheet
' default total rows to add 40

Const ServiceGroupColumn As String = "$H"
Const FirstDataRow As Integer = 12


Dim iRow As Long
Dim rowsToAdd As Integer
Dim LastRow As Long
Dim i As Integer
Dim rng As Range
Dim SvcGrpNum As Long
'Dim SvcGrp As Long

SvcGrpNum = InputBox("Please input the the total number of Service Group
connections from the DNP", "Service Group Number", 40)


With ActiveWorkbook.Worksheets("VOD")
LastRow = .Cells(.Rows.count, ServiceGroupColumn).End(xlUp).Row

i = 1

For iRow = LastRow To FirstDataRow Step -1

i = i + 1
If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1,
ServiceGroupColumn).Value Then
Else

' If ((SvcGrpNum - i) / 2) And 1 Then
' SvcGrp = .Cells(iRow, ServiceGroupColumn).Value
' MsgBox ("Service Group" & " " & SvcGrp & " " & "has an odd
number of rows. Please add a row and start over.")
' Else

rowsToAdd = (SvcGrpNum - i) / 2


.Cells(iRow, ServiceGroupColumn).Resize(rowsToAdd).EntireRow.In sert



i = 1
End If
' End If

Next iRow

End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default adding some rows in the middle of adding some other rows

P.S. the service group is only column H. It is a type field with in this
sheet 16 rows each for SvcGrp 001, SvcGrp002, SvcGrp 003.... The problem I
am trying to solve very badly is adding rows to each service group to make a
total of 40. Additionally it must be half added to the end of each service
group and half added in the middle. I would really like some help cleaning
this code up. Other sheets have a total of 8 rows to start with or 12 but I
would be happy if it worked for 16.


tia,

"JLGWhiz" wrote:

You might need to put up a sample of your data base again so folks will know
what you mean by service group. What you are trying to do is a little
tricky, since the quantiy of rows per service group vary so widely. If they
were all the same, It would be a pretty simple code.

"Janis" wrote:

This macro does half of what I want it to do. I need it also to add the same
number of rows as on the insert line only this time in the middle of the
service group. Since it already added half of the rows at the end of the
first service group
how do I get it to go to the middle of the service group add the same number
of rows and not get out of step for the next service group?

tia,


Public Sub n2m4()

'adds new rows for connections to VOD sheet
' default total rows to add 40

Const ServiceGroupColumn As String = "$H"
Const FirstDataRow As Integer = 12


Dim iRow As Long
Dim rowsToAdd As Integer
Dim LastRow As Long
Dim i As Integer
Dim rng As Range
Dim SvcGrpNum As Long
'Dim SvcGrp As Long

SvcGrpNum = InputBox("Please input the the total number of Service Group
connections from the DNP", "Service Group Number", 40)


With ActiveWorkbook.Worksheets("VOD")
LastRow = .Cells(.Rows.count, ServiceGroupColumn).End(xlUp).Row

i = 1

For iRow = LastRow To FirstDataRow Step -1

i = i + 1
If .Cells(iRow, ServiceGroupColumn).Value = .Cells(iRow - 1,
ServiceGroupColumn).Value Then
Else

' If ((SvcGrpNum - i) / 2) And 1 Then
' SvcGrp = .Cells(iRow, ServiceGroupColumn).Value
' MsgBox ("Service Group" & " " & SvcGrp & " " & "has an odd
number of rows. Please add a row and start over.")
' Else

rowsToAdd = (SvcGrpNum - i) / 2


.Cells(iRow, ServiceGroupColumn).Resize(rowsToAdd).EntireRow.In sert



i = 1
End If
' End If

Next iRow

End With

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
Adding rows based on no of rows specified from a given position nanette Excel Worksheet Functions 1 July 9th 08 02:29 PM
Adding Rows Paul_of_Abingdon Excel Discussion (Misc queries) 5 February 22nd 08 10:48 PM
Adding five new rows every 40 rows in a spreadsheet? Olzki Excel Discussion (Misc queries) 8 May 18th 07 02:14 AM
Adding Rows offsets to working rows across two worksheets tom Setting up and Configuration of Excel 3 July 30th 06 07:54 PM
Adding new rows Paul Sheppard Excel Discussion (Misc queries) 2 July 28th 05 06:05 AM


All times are GMT +1. The time now is 11:03 AM.

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"