Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 542
Default VBA to insert a row with -999.99

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA to insert a row with -999.99

I've assumed, and coded things so that the split is based on values in column
A and you just need the 3 -999.99 entries on the row

Press [Alt]+[F11] to open the VB editor, use Insert -- Module to add a code
module, then copy the code below, do any editing you need to it, and run it
via Tools -- Macro -- Macros

As I always recommend, try this on a copy of your data first.

Sub InsertMarkerRows()
Const dataMarker = -999.99
Const columnToTest = "A"

Dim currentValue As Integer ' may have to change type
Dim lastRow As Long
Dim LC As Long ' Loop Counter

lastRow = Range(columnToTest & Rows.Count). _
End(xlUp).Row
currentValue = Range(columnToTest & lastRow).Value
For LC = lastRow To 2 Step -1
If Range(columnToTest & LC).Offset(-1, 0) _
< currentValue Then
Range(columnToTest & LC).EntireRow.Insert
Range(columnToTest & LC).Value = dataMarker
Range(columnToTest & LC).Offset(0, 1) _
= dataMarker
Range(columnToTest & LC).Offset(0, 2) _
= dataMarker
currentValue = Range(columnToTest & LC). _
Offset(-1, 0)
End If
Next
End Sub


"James" wrote:

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 542
Default VBA to insert a row with -999.99

I am having problems with this line of code it says I have a "Type Mismatch"

Dim currentValue As Integer 'may have to change type

currentValue = Range(columnToTest & lastRow).Value

What should I change the "type" to.

Thank you

"JLatham" wrote:

I've assumed, and coded things so that the split is based on values in column
A and you just need the 3 -999.99 entries on the row

Press [Alt]+[F11] to open the VB editor, use Insert -- Module to add a code
module, then copy the code below, do any editing you need to it, and run it
via Tools -- Macro -- Macros

As I always recommend, try this on a copy of your data first.

Sub InsertMarkerRows()
Const dataMarker = -999.99
Const columnToTest = "A"

Dim currentValue As Integer ' may have to change type
Dim lastRow As Long
Dim LC As Long ' Loop Counter

lastRow = Range(columnToTest & Rows.Count). _
End(xlUp).Row
currentValue = Range(columnToTest & lastRow).Value
For LC = lastRow To 2 Step -1
If Range(columnToTest & LC).Offset(-1, 0) _
< currentValue Then
Range(columnToTest & LC).EntireRow.Insert
Range(columnToTest & LC).Value = dataMarker
Range(columnToTest & LC).Offset(0, 1) _
= dataMarker
Range(columnToTest & LC).Offset(0, 2) _
= dataMarker
currentValue = Range(columnToTest & LC). _
Offset(-1, 0)
End If
Next
End Sub


"James" wrote:

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA to insert a row with -999.99

I presumed your entries in column a were relatively small whole numbers
(integers). If they happen to get very large or if there is text in them,
then we need something else.

Let's go with the very generic type; Variant

So change
Dim currentValue As Integer
to
Dim currentValue As Variant

hopefully that'll handle things for you.

"James" wrote:

I am having problems with this line of code it says I have a "Type Mismatch"

Dim currentValue As Integer 'may have to change type

currentValue = Range(columnToTest & lastRow).Value

What should I change the "type" to.

Thank you

"JLatham" wrote:

I've assumed, and coded things so that the split is based on values in column
A and you just need the 3 -999.99 entries on the row

Press [Alt]+[F11] to open the VB editor, use Insert -- Module to add a code
module, then copy the code below, do any editing you need to it, and run it
via Tools -- Macro -- Macros

As I always recommend, try this on a copy of your data first.

Sub InsertMarkerRows()
Const dataMarker = -999.99
Const columnToTest = "A"

Dim currentValue As Integer ' may have to change type
Dim lastRow As Long
Dim LC As Long ' Loop Counter

lastRow = Range(columnToTest & Rows.Count). _
End(xlUp).Row
currentValue = Range(columnToTest & lastRow).Value
For LC = lastRow To 2 Step -1
If Range(columnToTest & LC).Offset(-1, 0) _
< currentValue Then
Range(columnToTest & LC).EntireRow.Insert
Range(columnToTest & LC).Value = dataMarker
Range(columnToTest & LC).Offset(0, 1) _
= dataMarker
Range(columnToTest & LC).Offset(0, 2) _
= dataMarker
currentValue = Range(columnToTest & LC). _
Offset(-1, 0)
End If
Next
End Sub


"James" wrote:

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 542
Default VBA to insert a row with -999.99

Thank you very much it works and this well help a lot.

"JLatham" wrote:

I presumed your entries in column a were relatively small whole numbers
(integers). If they happen to get very large or if there is text in them,
then we need something else.

Let's go with the very generic type; Variant

So change
Dim currentValue As Integer
to
Dim currentValue As Variant

hopefully that'll handle things for you.

"James" wrote:

I am having problems with this line of code it says I have a "Type Mismatch"

Dim currentValue As Integer 'may have to change type

currentValue = Range(columnToTest & lastRow).Value

What should I change the "type" to.

Thank you

"JLatham" wrote:

I've assumed, and coded things so that the split is based on values in column
A and you just need the 3 -999.99 entries on the row

Press [Alt]+[F11] to open the VB editor, use Insert -- Module to add a code
module, then copy the code below, do any editing you need to it, and run it
via Tools -- Macro -- Macros

As I always recommend, try this on a copy of your data first.

Sub InsertMarkerRows()
Const dataMarker = -999.99
Const columnToTest = "A"

Dim currentValue As Integer ' may have to change type
Dim lastRow As Long
Dim LC As Long ' Loop Counter

lastRow = Range(columnToTest & Rows.Count). _
End(xlUp).Row
currentValue = Range(columnToTest & lastRow).Value
For LC = lastRow To 2 Step -1
If Range(columnToTest & LC).Offset(-1, 0) _
< currentValue Then
Range(columnToTest & LC).EntireRow.Insert
Range(columnToTest & LC).Value = dataMarker
Range(columnToTest & LC).Offset(0, 1) _
= dataMarker
Range(columnToTest & LC).Offset(0, 2) _
= dataMarker
currentValue = Range(columnToTest & LC). _
Offset(-1, 0)
End If
Next
End Sub


"James" wrote:

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA to insert a row with -999.99

Glad to hear that the fix worked. Enjoy.

"James" wrote:

Thank you very much it works and this well help a lot.

"JLatham" wrote:

I presumed your entries in column a were relatively small whole numbers
(integers). If they happen to get very large or if there is text in them,
then we need something else.

Let's go with the very generic type; Variant

So change
Dim currentValue As Integer
to
Dim currentValue As Variant

hopefully that'll handle things for you.

"James" wrote:

I am having problems with this line of code it says I have a "Type Mismatch"

Dim currentValue As Integer 'may have to change type

currentValue = Range(columnToTest & lastRow).Value

What should I change the "type" to.

Thank you

"JLatham" wrote:

I've assumed, and coded things so that the split is based on values in column
A and you just need the 3 -999.99 entries on the row

Press [Alt]+[F11] to open the VB editor, use Insert -- Module to add a code
module, then copy the code below, do any editing you need to it, and run it
via Tools -- Macro -- Macros

As I always recommend, try this on a copy of your data first.

Sub InsertMarkerRows()
Const dataMarker = -999.99
Const columnToTest = "A"

Dim currentValue As Integer ' may have to change type
Dim lastRow As Long
Dim LC As Long ' Loop Counter

lastRow = Range(columnToTest & Rows.Count). _
End(xlUp).Row
currentValue = Range(columnToTest & lastRow).Value
For LC = lastRow To 2 Step -1
If Range(columnToTest & LC).Offset(-1, 0) _
< currentValue Then
Range(columnToTest & LC).EntireRow.Insert
Range(columnToTest & LC).Value = dataMarker
Range(columnToTest & LC).Offset(0, 1) _
= dataMarker
Range(columnToTest & LC).Offset(0, 2) _
= dataMarker
currentValue = Range(columnToTest & LC). _
Offset(-1, 0)
End If
Next
End Sub


"James" wrote:

I have a file that needs to go into my application but all the data is
grouped together. My application will recognize it is moved on to a new data
set when it see's -999.99, and the application is smart enough to say hey
this an entirely new data different from the data above it.

Here is generic example of what I have:

23 95.6 10003
23 80 650
23 2 897
49 600 10000
49 23 11

Here is what I would like to have:
23 95.6 10003
23 80 650
23 2 897
-999.99 -999.99 -999.99
49 600 10000
49 23 11

So whenever the value changes in column A to a new value I need it to insert
a new row of data that have the values of -999.99.

Thank you for the help.

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
Cannot insert worksheet in exel - not available in insert menu pedro39 Excel Worksheet Functions 1 July 24th 08 12:09 PM
insert row / insert column command buttons fairgreen Excel Worksheet Functions 1 October 29th 07 02:41 PM
How can I insert a date with an icon (calendar) insert Alfredo Mederico[_2_] Excel Discussion (Misc queries) 4 September 21st 07 01:20 AM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM


All times are GMT +1. The time now is 07:56 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"