Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Insert Row using Macro, Group By Date

I am pulling data from a sql database and would like to write a macro
to insert a date after each month. Example

Befo
4/5/03
4/6/03
5/2/03
5/12/03
5/23/03
6/1/03

After
4/5/03
4/6/03

5/2/03
5/12/03
5/23/03

6/1/03

How would go about coding this?

Thanks in Advance!
Jason
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Insert Row using Macro, Group By Date

Sub aaTester9()
Set rng = ActiveCell.Offset(1, 0)
Do While Not Application.CountA(rng.Resize(2, 1)) = 0
If Month(rng) < Month(rng.Offset(-1, 0)) Then
rng.EntireRow.Insert
End If
Set rng = rng.Offset(1, 0)
Loop

End Sub

select the cell at the top of the column.

--
Regards,
Tom Ogilvy




"JRW" wrote in message
om...
I am pulling data from a sql database and would like to write a macro
to insert a date after each month. Example

Befo
4/5/03
4/6/03
5/2/03
5/12/03
5/23/03
6/1/03

After
4/5/03
4/6/03

5/2/03
5/12/03
5/23/03

6/1/03

How would go about coding this?

Thanks in Advance!
Jason



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Insert Row using Macro, Group By Date

Before you add that extra row, think about not doing it. Maybe you could just
double the rowheight of the next row. It'll give the appearance of double
spacing, but it might make other stuff easier (sorting/pivottables/charts).

Option Explicit

Sub testme01()

Dim iRow As Long
Dim firstRow As Long
Dim lastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")
With wks
firstRow = 2
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = lastRow To firstRow Step -1
If Month(.Cells(iRow, "A").Value) _
< Month(.Cells(iRow - 1, "A").Value) _
Or Year(.Cells(iRow, "A").Value) _
< Year(.Cells(iRow - 1, "A").Value) Then
'.Rows(iRow).Insert
.Rows(iRow).RowHeight = 2 * .Rows(iRow).RowHeight
End If
Next iRow
End With

End Sub

(And I added a check to see if the year changed, but the month stayed the same)

JRW wrote:

I am pulling data from a sql database and would like to write a macro
to insert a date after each month. Example

Befo
4/5/03
4/6/03
5/2/03
5/12/03
5/23/03
6/1/03

After
4/5/03
4/6/03

5/2/03
5/12/03
5/23/03

6/1/03

How would go about coding this?

Thanks in Advance!
Jason


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Insert Row using Macro, Group By Date

What a left-field thought<vbg.

Bob

"Dave Peterson" wrote in message
...
Before you add that extra row, think about not doing it. Maybe you could

just
double the rowheight of the next row. It'll give the appearance of double
spacing, but it might make other stuff easier

(sorting/pivottables/charts).

Option Explicit

Sub testme01()

Dim iRow As Long
Dim firstRow As Long
Dim lastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")
With wks
firstRow = 2
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = lastRow To firstRow Step -1
If Month(.Cells(iRow, "A").Value) _
< Month(.Cells(iRow - 1, "A").Value) _
Or Year(.Cells(iRow, "A").Value) _
< Year(.Cells(iRow - 1, "A").Value) Then
'.Rows(iRow).Insert
.Rows(iRow).RowHeight = 2 * .Rows(iRow).RowHeight
End If
Next iRow
End With

End Sub

(And I added a check to see if the year changed, but the month stayed the

same)

JRW wrote:

I am pulling data from a sql database and would like to write a macro
to insert a date after each month. Example

Befo
4/5/03
4/6/03
5/2/03
5/12/03
5/23/03
6/1/03

After
4/5/03
4/6/03

5/2/03
5/12/03
5/23/03

6/1/03

How would go about coding this?

Thanks in Advance!
Jason


--

Dave Peterson



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
Insert blank row macro after a break in a group Gord Dibben Excel Discussion (Misc queries) 0 November 5th 09 09:54 PM
Macro to Insert Current Date into cell - Macro to "Save As" Guy[_2_] Excel Worksheet Functions 4 December 12th 08 08:20 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
Insert date in macro George Gee New Users to Excel 12 April 17th 06 05:44 AM
How do I insert the date using a macro tara0801 Excel Discussion (Misc queries) 4 February 10th 05 09:09 PM


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