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

Hello

I have a formula I am trying to put into vba format. I have the formula
working fine in the cells themselves, but it takes a long time to calculate
and recalculate.

Can anyone help me put this formula into the proper syntax?

There is a function called ColumnLetter that returns only the column letter.

Code:
x = Application.Evaluate("If($H" & cell.Row & "=" & 
ColumnLetter(Range(cell.Address)) & """$1"" ,"" - 
"",Sum(If(Countif(Offset(Numbers!$B2,Row(Indirect(""2:1091""))=1,0,1,5),$H" & 
cell.Row & 
")0,Countif(Offset(Numbers!$B$2,Row(Indirect(""2:1091""))-1,0,1,5)," & 
ColumnLetter(Range(cell.Address)) & "$1))))")

Function ColumnLetter(rngCell As Range) As String
    ColumnLetter = Replace(rngCell.Address(0, 0), rngCell.Row, "")
End Function
Here is a sample formula taken from a cell: (Entered as an array formula).

=IF($H2=J$1,"-",SUM(IF(COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT( "2:1091"))-1,0,1,5),$H2)0,
COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT("2:1091") )-1,0,1,5),J$1))))

Thank you so much
Terry
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default VBA / Formula

this part looks wrong to me. you have a columnLetter and then an address instead
of a row
ColumnLetter(Range(cell.Address))

i improvised a little, but maybe it will help you

Range("F2").FormulaArray = "=If($H" & cell.Row & "=" & ColumnLetter & cell.Row _
& ", " & """-""" & ",Sum(If(Countif(Offset(Numbers!$B2,Row(Indire ct(" & _
"""2:1091""" & "))=1,0,1,5),$H" & cell.Row & _
")0,Countif(Offset(Numbers!$B$2,Row(Indirect( " & """2:1091""" &
"))-1,0,1,5)," _
& ColumnLetter & cell.Row & "))))"

--


Gary


"ITperson" wrote in message
...
Hello

I have a formula I am trying to put into vba format. I have the formula
working fine in the cells themselves, but it takes a long time to calculate
and recalculate.

Can anyone help me put this formula into the proper syntax?

There is a function called ColumnLetter that returns only the column letter.

Code:
 x = Application.Evaluate("If($H" & cell.Row & "=" &
 ColumnLetter(Range(cell.Address)) & """$1"" ,"" -
 "",Sum(If(Countif(Offset(Numbers!$B2,Row(Indirect(""2:1091""))=1,0,1,5),$H" &
 cell.Row &
 ")0,Countif(Offset(Numbers!$B$2,Row(Indirect(""2:1091""))-1,0,1,5)," &
 ColumnLetter(Range(cell.Address)) & "$1))))")

 Function ColumnLetter(rngCell As Range) As String
    ColumnLetter = Replace(rngCell.Address(0, 0), rngCell.Row, "")
 End Function


Here is a sample formula taken from a cell: (Entered as an array formula).

=IF($H2=J$1,"-",SUM(IF(COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT( "2:1091"))-1,0,1,5),$H2)0,
COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT("2:1091") )-1,0,1,5),J$1))))

Thank you so much
Terry



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA / Formula

As I told you on MrExcel, evaluating a formula in VBA will not be quicker
than creating WS formulae. It may be a one-off but it will also not
recalculate.

A re-design seems more appropriate as suggested by someone else.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"ITperson" wrote in message
...
Hello

I have a formula I am trying to put into vba format. I have the formula
working fine in the cells themselves, but it takes a long time to
calculate
and recalculate.

Can anyone help me put this formula into the proper syntax?

There is a function called ColumnLetter that returns only the column
letter.

Code:
 x = Application.Evaluate("If($H" & cell.Row & "=" &
 ColumnLetter(Range(cell.Address)) & """$1"" ,"" -
 "",Sum(If(Countif(Offset(Numbers!$B2,Row(Indirect(""2:1091""))=1,0,1,5),$H" 
 &
 cell.Row &
 ")0,Countif(Offset(Numbers!$B$2,Row(Indirect(""2:1091""))-1,0,1,5)," &
 ColumnLetter(Range(cell.Address)) & "$1))))")

 Function ColumnLetter(rngCell As Range) As String
    ColumnLetter = Replace(rngCell.Address(0, 0), rngCell.Row, "")
 End Function


Here is a sample formula taken from a cell: (Entered as an array formula).

=IF($H2=J$1,"-",SUM(IF(COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT( "2:1091"))-1,0,1,5),$H2)0,
COUNTIF(OFFSET(Numbers!$B$2,ROW(INDIRECT("2:1091") )-1,0,1,5),J$1))))

Thank you so much
Terry



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
Regression Leverage Formula (Jerry W. Lewis or Mike Middleton)already have DFITS formula PJ[_3_] Excel Worksheet Functions 2 June 2nd 10 03:45 PM
Excel 2002 Formula: Urgent Conditional Formula Required Right Away - if possible blue[_2_] Excel Discussion (Misc queries) 2 July 11th 07 06:08 PM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM
Cell doesn't show formula result - it shows formula (CTRL + ' doe. o0o0o0o Excel Worksheet Functions 6 November 19th 04 03:13 PM
Commenting custom formula fields/formula on formula editor Muxer Excel Programming 2 July 24th 03 01:02 AM


All times are GMT +1. The time now is 02:13 AM.

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"