!
-now select the cell you want to process
had to be
-now select the cells you want to process
Main Topics
Browse All TopicsI have a rather large file containing information that has been sorted by District (Example below). There are currently no blank rows between the districts.
DISTRICT
255
255
255
166
166
168
170
170
170
I would like to do 2 things in no particular order:
1) Insert a blank row every time the district changes.
2) Number each district (ie. 255 is 1, 166 is 2, 168 is 3 etc...)
Surely there is some automated way to do this with a macro instead of going down through the spreadsheet manually which would take hours.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Paperboy2002
I am new in this area but the following codes work. I put the district codes in Column A and the macro enters the numbers in Column B. Therefore, in “ Cells(i, 1)” and “Cells(i, 2)” (lines 4, 5,7, and 10) I put in 1 standing for Column A and 2 for Column B. You may change it accordingly. For example, if district codes are in column E and you want the numbers in column F, you should replace with 5 and 6 respectively (that should look Cells(i, 5)” and “Cells(i, 6)”). Also, in “For i = 2 To 8”, I assume the data start at row 2 and end at row 8. You should change it accordingly, too.
Sub district()
n = 1
For i = 2 To 8
If Cells(i, 1) <> "" Then
Cells(i, 2) = n
End If
If Cells(i, 1) = "" Then
n = n + 1
End If
If Cells(i, 1) <> Cells(i + 1, 1)And Cells(i, 1) <> "" Then
Cells(i + 1, 1).EntireRow.Insert Shift:=xlDown
End If
Next i
End Sub
Hello Paperboy2002,
this question is open for more then 4 weeks
it is time to clean up or revitalize
if not stated otherwise
my recommendation for the moderator will be
-PAQ
-points to bruintje
-this will be finalized by an EE Moderator
-with no further update (07.12.2002)
PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER
HAGD:O)Bruintje
posted by ToolzEE v1.0
Business Accounts
Answer for Membership
by: bruintjePosted on 2002-10-15 at 08:00:57ID: 7334621
Hello Paperboy2002,
you can try this
-open the VB Editor with ALT +F11
-then insert a new module
-paste the code
Option Explicit
Public Sub DistrictSampler()
Dim c As Range
Dim i As Long
Dim sVal As String
i = 1
sVal = Selection(1, 1)
For Each c In Selection
If c <> sVal Then
sVal = c
c.Offset(0, 0).Insert Shift:=xlDown
i = i + 1
End If
c.Value = i
Next
End Sub
-save and close this editor
-now select the cell you want to process
-and choose tools | macro | macros| run | TextBold
HAGD:O)Bruintje