Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jaz Jaz is offline
external usenet poster
 
Posts: 1
Default Macro error why?

Spreadsheet contains a data range from cell A4 that is
refreshed regularly with updated data. Column A contains a
list of cities and is sorted A-Z. I am trying to cretae
macor that will insert a blank row between each change of
city all the way down. Cuurent attempt as follows but does
not work?

Dim strstate As String

strtate = ActiveCell
ActiveCell("a4").Select
Do
If strstate = ActiveCell.Offset(-1, 0) Then
ActiveCell.Offset(1, 0).Select
Else
rowSelection.Insert Shift:=xlDown
ActiveCell.Offset(3, 0).Select
Loop Until ActiveCell.Offset(2, 0) = Empty

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Macro error why?

Jaz, give this a try

Sub Insert_row()
Application.ScreenUpdating = False
Dim Rng As Range
Dim x As Long
Set Rng = Range("A4:A" & Range("A65536").End(xlUp).Row)
For x = Rng.Rows.Count To 2 Step -1
If Rng.Cells(x, 1).Offset(-1, 0).Value < Rng.Cells(x, 1).Value Then
Rng.Cells(x, 1).Resize(1, 1).EntireRow.Insert Shift:=xlDown
End If
Next x
Application.ScreenUpdating = True
End Sub


--
Paul B
Always backup your data before trying something new
Using Excel 2000 & 97
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
"Jaz" wrote in message
...
Spreadsheet contains a data range from cell A4 that is
refreshed regularly with updated data. Column A contains a
list of cities and is sorted A-Z. I am trying to cretae
macor that will insert a blank row between each change of
city all the way down. Cuurent attempt as follows but does
not work?

Dim strstate As String

strtate = ActiveCell
ActiveCell("a4").Select
Do
If strstate = ActiveCell.Offset(-1, 0) Then
ActiveCell.Offset(1, 0).Select
Else
rowSelection.Insert Shift:=xlDown
ActiveCell.Offset(3, 0).Select
Loop Until ActiveCell.Offset(2, 0) = Empty

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro error why?

Try this



For x = 2 To 100000

If Range("A" & x) = "" Then Exit For
If Range("A" & x) < Range("A" & x + 1) Then
Range("A" & x + 1).Insert Shift:=xlDown
x = x + 1
End If

Next x




--

"Jaz" wrote in message
...
Spreadsheet contains a data range from cell A4 that is
refreshed regularly with updated data. Column A contains a
list of cities and is sorted A-Z. I am trying to cretae
macor that will insert a blank row between each change of
city all the way down. Cuurent attempt as follows but does
not work?

Dim strstate As String

strtate = ActiveCell
ActiveCell("a4").Select
Do
If strstate = ActiveCell.Offset(-1, 0) Then
ActiveCell.Offset(1, 0).Select
Else
rowSelection.Insert Shift:=xlDown
ActiveCell.Offset(3, 0).Select
Loop Until ActiveCell.Offset(2, 0) = Empty

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
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Macro Error The Toasterman Excel Discussion (Misc queries) 4 June 30th 06 01:44 PM
Macro error : Application-defined or object-defined error Joe Excel Discussion (Misc queries) 3 January 27th 06 02:32 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


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