INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Insert Number of Excel rows based on a column

## Insert Number of Excel rows based on a column

(OP)
Hi all,

I have an excel sheet that looks like the following:-

Acacia Avenue
2
Beech Street
6
High Street
10

What I want to be able to do is create a worksheet that creates 2 rows for Acacia Avenue, 6 rows for Beech Street, and 10 for High Street

Is this easy to do? If so how!?!?

David.

### RE: Insert Number of Excel rows based on a column

Starting point:

Sheet1
A
Acacia Avenue
2
Beech Street
6
High Street
10

Code in Excel:

#### CODE

Option Explicit

Sub Macro1()

Dim intRow As Integer
Dim strStreet As String
Dim intNo As Integer

intRow = 1

Do While Sheet1.Range("A" & intRow).Value <> ""

If IsNumeric(Sheet1.Range("A" & intRow).Value) Then
Call PlaceInfo(strStreet, Sheet1.Range("A" & intRow).Value)
Else
strStreet = Sheet1.Range("A" & intRow).Value
End If

intRow = intRow + 1
Loop

End Sub

Private Sub PlaceInfo(ByRef strS As String, ByRef intN As Integer)
Dim i As Integer
Static intR As Integer
If intR = 0 Then intR = 1

For i = 1 To intN
Sheet2.Range("A" & intR).Value = strS
intR = intR + 1
Next i

End Sub 

Result:

Sheet2
A
Acacia Avenue
Acacia Avenue
Beech Street
Beech Street
Beech Street
Beech Street
Beech Street
Beech Street
High Street
High Street
High Street
High Street
High Street
High Street
High Street
High Street
High Street
High Street


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

### RE: Insert Number of Excel rows based on a column

I guess my solution is NOT what David wants...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

### RE: Insert Number of Excel rows based on a column

@Andy, if you notice, the OP seems to not to have a good record of replying to his own threads or any other threads.

Skip,

Just traded in my OLD subtlety...
for a NUance!

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!