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: 53
Default How to fill range with formula using VBA?

I have code that creates new worksheets using automation. I need to fill a
range in each worksheet with a formula after it is created. What I
currently have looks like this:

With xlapp.Workbooks(strXlsFile).Worksheets(sn(i))
lc = .Range("A1").SpecialCells(xlCellTypeLastCell).Colu mn
lr = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
.Cells(1).EntireRow.HorizontalAlignment = xlCenter
.Cells(1).EntireRow.Font.Bold = True
.Range("B2:B" & lr).Formula = "=AVERAGE(E2:AH2)"
End With

The problem is I don't know how many columns I'm going to have. So
"=AVERAGE(E2:AH2)" is just a guess - I could have more or less columns than
"AH". I have the value of the last column expressed as an integer in the
variable lc - but how do I use this? Is there a way to translate that value
to the corresponding letter value? The formula has to be a sting value to
fill down to the last column, correct?

This may be a simple question, but I have not worked with Excel to much...

Thanks.


 
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
Fill range don't change the formula, Help was no help. Please hel Trussell Excel Worksheet Functions 3 October 19th 08 04:30 AM
I Need a Formula to Auto-fill Phone Numbers in a Range twd3lr Excel Worksheet Functions 4 February 4th 05 08:38 PM
Formula to count the cells in a range that have a fill color. Slainteva Excel Discussion (Misc queries) 2 January 19th 05 08:25 PM
Formula to count the cells in a range that have a fill color. Molly F Excel Discussion (Misc queries) 2 January 19th 05 06:15 PM
Excel - formula to calculate colored fill cells within a range wi. MA Excel Worksheet Functions 1 January 7th 05 04:06 PM


All times are GMT +1. The time now is 08:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"