Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Enter Formula via VBA

Greetings
I have a file that is imported daily and it varies as to the number of lines
in the file each day. Using a macro I woud like find the next available row
and enter the following formula in ColH:ColAE (24 Cols)
=SUMPRODUCT(--($F$3:$F$66="Cat"),--($G$3:$G$66="Bird"),--
($C$3:$C$66<"Black"),--($C$3:$C$66<"White"),H3:H66)
The example file had 66 rows of data and this is the part that could change
each day.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Enter Formula via VBA

set rng = cells(rows.count,"H").End(xlup)(2)
rng.Resize(1,24).formulaR1C1 = "=Sumproduct(--(R3C5:R[-1]C5=""Cat"")," & _
"--(R3C6:R[-1]C6=""Bird""),--(R3C3:R[-1]C3<""Black"")," & _
"--(R3C3:R[-1]C3<""White""),R3C:R[-1]C)"

an alternative

set rng = cells(rows.count,"H").End(xlup)(2)
s = "=SUMPRODUCT(--($F$3:$F$66=""Cat""),--($G$3:$G$66" & _
"=""Bird""),--($C$3:$C$66<""Black"")," & _
"--($C$3:$C$66<""White""),H3:H66)"
s = Replace(s,"66",rng.offset(-1,0).row)
rng.Resize(1,24).Formula = s
--
Regards,
Tom Ogilvy


"Bobby" wrote in message
...
Greetings
I have a file that is imported daily and it varies as to the number of

lines
in the file each day. Using a macro I woud like find the next available

row
and enter the following formula in ColH:ColAE (24 Cols)
=SUMPRODUCT(--($F$3:$F$66="Cat"),--($G$3:$G$66="Bird"),--
($C$3:$C$66<"Black"),--($C$3:$C$66<"White"),H3:H66)
The example file had 66 rows of data and this is the part that could

change
each day.
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Enter Formula via VBA

Bobby wrote:
Greetings
I have a file that is imported daily and it varies as to the number of lines
in the file each day. Using a macro I woud like find the next available row
and enter the following formula in ColH:ColAE (24 Cols)
=SUMPRODUCT(--($F$3:$F$66="Cat"),--($G$3:$G$66="Bird"),--
($C$3:$C$66<"Black"),--($C$3:$C$66<"White"),H3:H66)
The example file had 66 rows of data and this is the part that could change
each day.
Thanks

--------------------

Tom gave you the "right" answer. Here's a cheezier one which is perhaps easier
to understand:

dim LastRow as Long
dim ColIndex as Long
LastRow = Range("H1").end(xlDown).row
for ColIndex = 8 to 31
cells(LastRow,ColIndex) = "=SUMPRODUCT(...etc...."
next ColIndex

Bill

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Enter Formula via VBA

Bobby wrote:
Greetings
I have a file that is imported daily and it varies as to the number of lines
in the file each day. Using a macro I woud like find the next available row
and enter the following formula in ColH:ColAE (24 Cols)
=SUMPRODUCT(--($F$3:$F$66="Cat"),--($G$3:$G$66="Bird"),--
($C$3:$C$66<"Black"),--($C$3:$C$66<"White"),H3:H66)
The example file had 66 rows of data and this is the part that could change
each day.
Thanks

--------------------

Tom gave you the "right" answer. Here's a cheezier one which is perhaps easier
to understand:

dim LastRow as Long
dim ColIndex as Long
LastRow = Range("H1").end(xlDown).row
for ColIndex = 8 to 31
cells(LastRow + 1,ColIndex) = "=SUMPRODUCT(...etc...."
next ColIndex

Bill (Small change edited into code)
Reply
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
When I enter a formula, Excel shows the formula not the results Pat Adams Excel Worksheet Functions 5 April 4th 23 11:18 AM
When I enter a formula it shows the formula not the result Dominic Excel Discussion (Misc queries) 2 August 4th 08 12:08 PM
can you wrap formula results via a formula eg. Alt Enter Bryan McHugh Excel Discussion (Misc queries) 5 March 8th 07 12:52 AM
What does hitting Ctrl + Shift + Enter to enter a formula do??? Help a n00b out. qwopzxnm Excel Worksheet Functions 2 October 20th 05 09:06 PM
Cannot enter formula in a cell after removing a circular formula Big Corona Excel Worksheet Functions 0 April 5th 05 06:07 PM


All times are GMT +1. The time now is 08:41 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"