View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT[_6_] JT[_6_] is offline
external usenet poster
 
Posts: 2
Default Excel VBA - Inserting associated values in a report Please Help :)

Here's my sample data:
Column A, Column E on Worksheet ("CO")
"555-555-5555","Jim"
"123-456-7890","Jim"
"987-654-3210","Jim"
"444-444-4444","Kandy"
"333-333-3333","Kandy"
"222-222-2222","Steve"

Hi all I could really use some help on this. I'm printing reports in
excel based on values in a worksheet. The report desired prints the
name of the person along with all phone #'s associated with that
person.. Therefore the first report would Generate a page that says
"Jim" and the 3 phone numbers above associated with him, and then the
second would say Kandy with her two numbers and the last Steve with
one.

I'm using VBA to do this because this is basically automating an
annoying process here at work. So far I can get the report to print
for each unique name, but I'm having an issue figuring how out to add
those related phone numbers to each report. Here's the code I'm using:

Private Sub CommandButton1_Click()
Dim main, telephone As Range, i, k As Integer

i = 0
k = 1

Set main = Sheet1.Range("E" & k)
Set telephone = Worksheets("CO").Range("A27:I33")

Worksheets("CO").Range("B9").Value = Sheet1.Range("E" & k).Text
'name of person

Do While main.Offset(i, 0) < ""
If Sheet1.Range("E" & k).Text <
Worksheets("CO").Range("B9").Value Then
Worksheets("CO").PrintOut
Worksheets("CO").Range("B9").Value = Sheet1.Range("E"
& k).Text 'update name
If Sheet1.Range("E" & k + 1).Text = "" Then
Worksheets("CO").PrintOut
End If
k = k + 1
i = i + 1
ClearCourtOrder
Loop

End Sub

That prints the reports fine but can anyone suggest how to add the
associated phone numbers onto the report as well? Ideally, I set up a
range called telephone from A27:I33 on "CO" and would like the numbers
listed in that range only. I really appreciate any insight on how to
approach this.