Referring to value in range

F

Forgone

I've created a macro that loops through a range of single values in a
column.
I'm trying to figure out whether its possible to have 4 columns in
each row of values and obtain the first, second and third value and
put the value of each in a specific cell.

The macro filters a bunch of data in a template and then creates a new
document from an .xlt file and copies the data into it, saves and
closes the file.

An Extract of the macro is:

Sub CreateReports()

For Each c In Range("loop.range")
Windows("2008-09 Budget Template - master.xls").Activate
Worksheets("BA Report").Activate
Worksheets("BA Report").Range("BCostCentre") = c.Value




This is ok as BCostCentre is 1 cell....

What I want to do is extend loop.range to 4 columns of unique values
that I want to report on and not sure how to code it.

I was thinking it would be something like....

Sub CreateReports()

Dim fname As Variant
Dim bname As Variant

For Each c In Range("loop.range")
Windows("2008-09 Budget Template - master.xls").Activate
Worksheets("BA Report").Activate
Worksheets("BA Report").Range("BCostCentre1") = c.Value(1)
Worksheets("BA Report").Range("BCostCentre2") = c.Value(2)
Worksheets("BA Report").Range("BCostCentre3") = c.Value(3)
Worksheets("BA Report").Range("BCostCentre4") = c.Value(4)

.......

then save the new file....


bname = "(" & Worksheets("BA Report").Range
("BCostCentreDescription").Value & ")"
fname = c.Value & " - " & bname & " - 08.09 BUDGET TEMPLATE" & ".xls"

.....

currently, the name of the file for this would be.... 2340100 -
Collection & Content Devel Div - 08.09 BUDGET TEMPLATE.xls

What I'm hoping to do is to modify it too something like

fname = c.Value(1) &"-"& c.Value(2) &"-"& c.Value(3) &"-"& c.Value(4)
& " - " & bname & .......

is this the correct syntax or am I way out?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top