LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Looping through data and Populate template

Hi all,

I have a question about loop procedures. I have 2 ranges that contain
the following info

Range 1: PackageNames
Package1 $20.00
Package2 $30.00

Range 2: PackageDetail
Package1 Product 1
Package1 Product 2
Package1 Product 3
Package1 Product 4
Package2 Product 2
Package2 Product 3
Package2 Product 5
Package2 Product 6

And I use the following code to pick out the info in these 2 ranges and
place them in appropriate location in a tamplate, which is in a
difference tab. The template looks like this.

Package1 -----------------PackPrice
-------------------------------------------------
Product1
Product2
Product3
Product4

In this template, the "Product.." area is a large range called
"TmplPackDetail"
Here is my code, which don't work...:( .

This code is intented to loop through the two ranges, save their
content to 2 arrays, then compare the values. When the package name in
Array 1 = package name in array 2, set the value of first cell in the
template = to the first product in the range2. Then repeat it self.

Ideally, when the packname are not equal, I want excel to export the
template to MS Word, then clear template, then run the same loop again
to populate a diffent package.But we are not there yet, since the first
part of the code is not even working.

I'm familiar with Access coding, not Excel. I really need help with
this. I really appreciate your help and time.

Sub Template()

'Generate PackNames Array
Dim PackageName() As String
Dim intPackNCount As Integer
intPackNCount = Range("PackageNames").Rows.Count
ReDim PackageName(intPackNCount)

Dim i As Integer
For i = 1 To intPackNCount
PackageName(i) = Range("PackageNames").Cells(i + 1,
1).Value
Next i

'Generate PackDetails Array
Dim PackageDName() As String
Dim intPackDCount As Integer
intPackDCount = Range("PackageDetails").Rows.Count
ReDim PackageDName(intPackDCount)

Dim j As Integer
For j = 1 To intPackDCount
PackageDName(j) = Range("PackageDetails").Cells(j + 1,
1).Value
Next j

'If arguments
For i = 1 To intPackCount
For j = 1 To intPackDCount
If PackageName(i) = PackageDName(j) Then
Range("TmplPackDetail").Cells(i + 1, 1).Value =
PackageDName(j)
Else
Exit Sub
End If
Next j
Next i

End Sub

 
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
Populate a template for each customer CER Excel Discussion (Misc queries) 0 December 22nd 09 03:08 PM
Populate central worksheet template from multiple worksheets wcurtis Excel Discussion (Misc queries) 0 December 24th 08 10:10 PM
HOW DO I POPULATE AN EXCEL TEMPLATE USING DATABASE trent Excel Worksheet Functions 7 February 28th 08 07:39 PM
How can I have Excel cells populate a Word label template? MS Questionnairess Excel Discussion (Misc queries) 1 June 8th 06 01:26 AM
How do I populate 2006 calendar into the attendance template. Lmorford Excel Worksheet Functions 0 March 8th 06 07:51 PM


All times are GMT +1. The time now is 03:10 PM.

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"