Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Can I write a macro to insert a row after a data change?

After running a database query, the default output is exported to an Excel
file. The format is such that there are unique column headers, and there are
multiple rows for each "record" because there is a unique record in a column
on each row.

Column A is for an ID number. Then there may be 6 rows of the same ID
number because there is a unique record value in Column H for that ID number.
So, Column A has perhaps 6 or 7 rows of the same ID number, before the next
ID number is shown.

I need to find a way to write a macro or VB to query Column A and insert a
row when there is a change in data. For example, when the ID number changes
from 1 to 2, or from "1-3" to "1-4".

Any suggestions?
Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Can I write a macro to insert a row after a data change?

This may work as long as the ID numbers go in ascending order

Sub untested()
Dim rngID As Range
Dim i As Long
Set rngID = ActiveSheet.Range(Cells(2, "A"), _
Cells(Rows.Count, "A").End(xlUp))
With rngID
For i = .Rows.Count To 1 Step -1
If .Cells(i) .Cells(i).Offset(-1, 0) Then
.Cells(i).EntireRow.Insert
End If
Next i
End With
End Sub
"Kevin1061" wrote:

After running a database query, the default output is exported to an Excel
file. The format is such that there are unique column headers, and there are
multiple rows for each "record" because there is a unique record in a column
on each row.

Column A is for an ID number. Then there may be 6 rows of the same ID
number because there is a unique record value in Column H for that ID number.
So, Column A has perhaps 6 or 7 rows of the same ID number, before the next
ID number is shown.

I need to find a way to write a macro or VB to query Column A and insert a
row when there is a change in data. For example, when the ID number changes
from 1 to 2, or from "1-3" to "1-4".

Any suggestions?
Thanks!!

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
Write Macro to Fix Data Alignment (Data dump from Crystal to Excel Karin Excel Discussion (Misc queries) 2 September 22nd 09 05:31 PM
change colorIndex, help me write an easy macro Matt_70501 Excel Programming 4 May 28th 06 07:38 PM
how do i write a macro to change font color with live data? CJS Excel Programming 1 May 26th 06 06:28 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
How to read a SQL Table into Excel change the data and write back into SQL Belinda Excel Programming 1 June 10th 04 10:18 AM


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