PC Review


Reply
Thread Tools Rate Thread

Array Formula in VBA

 
 
Bigfoot17
Guest
Posts: n/a
 
      7th Apr 2008
I have been using a array formula like this to 'count' the number of cells
that =1 in one column and >25 in the second column. The file the cell is
checking is in another file.
{=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[fiel2.xls]Sheet3'!$N$2:$N$1800>50))}

Currently when the file opens it asks if I want to update and then it checks
file2 and enters the data. Simple enough. But now I am writing code to work
at the press of a macro button, and I am not making progress.

Workbooks("file1.xls").Sheets("Sheet1").Activate
Range("B6").FormulaArray =
{=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3!$N$2:$N$1800>50))}

Any guidance is appreciated.

 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      7th Apr 2008
Perhaps setting Application.DisplayAlerts to False before running your code
and back to True afterwards will handle your problem. If it works for this
situation, setting DisplayAlerts to False will mean any dialog boxes that
would be have been displayed will not display and the default button will be
selected automatically (well, for your case... this works the opposite for
SaveAs).

Rick


"Bigfoot17" <(E-Mail Removed)> wrote in message
news:17721E8C-5DFE-4FE4-925D-(E-Mail Removed)...
>I have been using a array formula like this to 'count' the number of cells
> that =1 in one column and >25 in the second column. The file the cell is
> checking is in another file.
> {=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[fiel2.xls]Sheet3'!$N$2:$N$1800>50))}
>
> Currently when the file opens it asks if I want to update and then it
> checks
> file2 and enters the data. Simple enough. But now I am writing code to
> work
> at the press of a macro button, and I am not making progress.
>
> Workbooks("file1.xls").Sheets("Sheet1").Activate
> Range("B6").FormulaArray =
> {=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3!$N$2:$N$1800>50))}
>
> Any guidance is appreciated.
>


 
Reply With Quote
 
Net_prof
Guest
Posts: n/a
 
      7th Apr 2008
Just think thru your steps logically:

1. Open the 2nd file - you can't activate the 2nd file unless it's already
open.
2. Initialize the array
3. Loop thru each cell in 2nd file, updating the array if your condition is
met.
4. Close the 2nd file.
5. Write the results to the cell(s).

Feel free to contact me direct if you have any additional questions.

(E-Mail Removed)


"Bigfoot17" wrote:

> I have been using a array formula like this to 'count' the number of cells
> that =1 in one column and >25 in the second column. The file the cell is
> checking is in another file.
> {=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[fiel2.xls]Sheet3'!$N$2:$N$1800>50))}
>
> Currently when the file opens it asks if I want to update and then it checks
> file2 and enters the data. Simple enough. But now I am writing code to work
> at the press of a macro button, and I am not making progress.
>
> Workbooks("file1.xls").Sheets("Sheet1").Activate
> Range("B6").FormulaArray =
> {=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3!$N$2:$N$1800>50))}
>
> Any guidance is appreciated.
>

 
Reply With Quote
 
Bigfoot17
Guest
Posts: n/a
 
      7th Apr 2008
I am afraid I was not clear so I will take another stab at it.

I currently have a array formula in file1.xls on sheet1 in cell B6
={=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3'!$N$2:$N$1800>50))}

This works fine, but now I need to get the same data into the same cell
(from file2) with VBA and cannot get the proper syntax.
 
Reply With Quote
 
kounoike
Guest
Posts: n/a
 
      8th Apr 2008
Try this one. Assuming file1.xls and file2.xls are in the same folder.

Range("B6").FormulaArray =
"=SUM(([file2.xls]Sheet3!$H$2:$H$1800=1)*([file2.xls]Sheet3!$N$2:$N$1800>50))"

keiji

"Bigfoot17" <(E-Mail Removed)> wrote in message
news:3E2B5537-DED5-4DDF-8153-(E-Mail Removed)...
>I am afraid I was not clear so I will take another stab at it.
>
> I currently have a array formula in file1.xls on sheet1 in cell B6:
> ={=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3'!$N$2:$N$1800>50))}
>
> This works fine, but now I need to get the same data into the same cell
> (from file2) with VBA and cannot get the proper syntax.


 
Reply With Quote
 
Bigfoot17
Guest
Posts: n/a
 
      8th Apr 2008
Give this person a donut! Thanks it got me where i needed to be. My final
line was:
Range("B6").FormulaArray =
"=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]sheet3'!$K$2:$K$1800>25))"
I wasn't far off in figuring it out in my first post, but I was missing a
single quote and threw everything off. Thanks.

"kounoike" wrote:

> Try this one. Assuming file1.xls and file2.xls are in the same folder.
>
> Range("B6").FormulaArray =
> "=SUM(([file2.xls]Sheet3!$H$2:$H$1800=1)*([file2.xls]Sheet3!$N$2:$N$1800>50))"
>
> keiji
>
> "Bigfoot17" <(E-Mail Removed)> wrote in message
> news:3E2B5537-DED5-4DDF-8153-(E-Mail Removed)...
> >I am afraid I was not clear so I will take another stab at it.
> >
> > I currently have a array formula in file1.xls on sheet1 in cell B6:
> > ={=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3'!$N$2:$N$1800>50))}
> >
> > This works fine, but now I need to get the same data into the same cell
> > (from file2) with VBA and cannot get the proper syntax.

>
>

 
Reply With Quote
 
kounoike
Guest
Posts: n/a
 
      9th Apr 2008
you're welcome. in this case i think it would work without single quote, but
adding single quote is better way.

keiji

"Bigfoot17" <(E-Mail Removed)> wrote in message
news:2E844063-3D72-4CE3-8916-(E-Mail Removed)...
> Give this person a donut! Thanks it got me where i needed to be. My final
> line was:
> Range("B6").FormulaArray =
> "=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]sheet3'!$K$2:$K$1800>25))"
> I wasn't far off in figuring it out in my first post, but I was missing a
> single quote and threw everything off. Thanks.
>
> "kounoike" wrote:
>
>> Try this one. Assuming file1.xls and file2.xls are in the same folder.
>>
>> Range("B6").FormulaArray =
>> "=SUM(([file2.xls]Sheet3!$H$2:$H$1800=1)*([file2.xls]Sheet3!$N$2:$N$1800>50))"
>>
>> keiji
>>
>> "Bigfoot17" <(E-Mail Removed)> wrote in message
>> news:3E2B5537-DED5-4DDF-8153-(E-Mail Removed)...
>> >I am afraid I was not clear so I will take another stab at it.
>> >
>> > I currently have a array formula in file1.xls on sheet1 in cell B6:
>> > ={=SUM(('[file2.xls]Sheet3'!$H$2:$H$1800=1)*('[file2.xls]Sheet3'!$N$2:$N$1800>50))}
>> >
>> > This works fine, but now I need to get the same data into the same cell
>> > (from file2) with VBA and cannot get the proper syntax.

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array formula SUMIF with 2D sum_range array Rich_84 Microsoft Excel Worksheet Functions 3 3rd Apr 2009 10:46 PM
Array formula: how to join 2 ranges together to form one array? Rich_84 Microsoft Excel Worksheet Functions 2 1st Apr 2009 06:38 PM
Difference between results of array formula and non-array, with IF(ISNUMBER) THOMAS CONLON Microsoft Excel Discussion 3 27th Aug 2006 10:22 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Microsoft Excel Programming 0 27th Jul 2005 03:59 PM
Array Formula - Use of OFFSET function with array argument Alan Microsoft Excel Worksheet Functions 2 11th Feb 2004 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 PM.