PC Review


Reply
Thread Tools Rate Thread

CSE formulas in vba(ie: averageif in Excel 2003)

 
 
=?Utf-8?B?TmVlZCBIZWxwIEZhc3Qh?=
Guest
Posts: n/a
 
      30th Mar 2007
I have a cse equation in a worksheet. I am trying to paste the equation to
multiple workbooks in a folder. My problem is when I do this since I can't
hit cntrl-shift-enter it returns an error. Is there a way in vba when it says
to paste as a formula for it to know to paste it as a cse formula? Here is
the complete code. Thanks


Sub Macro8()
Dim basebook As Workbook
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long
Dim SourceRcount As Long
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String
Dim Unprotectworksheet As Worksheet

SaveDriveDir = CurDir
MyPath = "D:\Profiles\cherring\My Documents\AllStates\New Folder"
ChDrive MyPath
ChDir MyPath

FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
rnum = 1

Do While FNames <> ""
If FNames <> basebook.Name Then
Set mybook = Workbooks.Open(FNames)
Set sourceRange =
basebook.Worksheets("NetWeatherResidualLookup").Range("A1:B10000")
SourceRcount = sourceRange.Rows.Count
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cells(rnum, "A")

With sourceRange
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cells(rnum, "A"). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Formula = sourceRange.Formula



Application.DisplayAlerts = False

mybook.Close ([True])
rnum = rnum
End If
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhcmxlcyBDaGlja2VyaW5n?=
Guest
Posts: n/a
 
      30th Mar 2007
CSE formulas are officially named "Array" formulas. Try
YourRange.FormulaArray = SomeArrayFormula
--
Charles Chickering

"A good example is twice the value of good advice."


"Need Help Fast!" wrote:

> I have a cse equation in a worksheet. I am trying to paste the equation to
> multiple workbooks in a folder. My problem is when I do this since I can't
> hit cntrl-shift-enter it returns an error. Is there a way in vba when it says
> to paste as a formula for it to know to paste it as a cse formula? Here is
> the complete code. Thanks
>
>
> Sub Macro8()
> Dim basebook As Workbook
> Dim mybook As Workbook
> Dim sourceRange As Range
> Dim destrange As Range
> Dim rnum As Long
> Dim SourceRcount As Long
> Dim FNames As String
> Dim MyPath As String
> Dim SaveDriveDir As String
> Dim Unprotectworksheet As Worksheet
>
> SaveDriveDir = CurDir
> MyPath = "D:\Profiles\cherring\My Documents\AllStates\New Folder"
> ChDrive MyPath
> ChDir MyPath
>
> FNames = Dir("*.xls")
> If Len(FNames) = 0 Then
> MsgBox "No files in the Directory"
> ChDrive SaveDriveDir
> ChDir SaveDriveDir
> Exit Sub
> End If
>
> Application.ScreenUpdating = False
> Set basebook = ThisWorkbook
> rnum = 1
>
> Do While FNames <> ""
> If FNames <> basebook.Name Then
> Set mybook = Workbooks.Open(FNames)
> Set sourceRange =
> basebook.Worksheets("NetWeatherResidualLookup").Range("A1:B10000")
> SourceRcount = sourceRange.Rows.Count
> Set destrange =
> mybook.Worksheets("NetWeatherResidualLookup").Cells(rnum, "A")
>
> With sourceRange
> Set destrange =
> mybook.Worksheets("NetWeatherResidualLookup").Cells(rnum, "A"). _
> Resize(.Rows.Count, .Columns.Count)
> End With
> destrange.Formula = sourceRange.Formula
>
>
>
> Application.DisplayAlerts = False
>
> mybook.Close ([True])
> rnum = rnum
> End If
> FNames = Dir()
> Loop
> ChDrive SaveDriveDir
> ChDir SaveDriveDir
> Application.ScreenUpdating = True
> End Sub
>

 
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
Is there an AVERAGEIF function in excel? lisab Microsoft Excel Misc 5 9th Nov 2009 06:46 PM
Excel AverageIF issue... PLEASE HELP! martinezr4@gmail.com Microsoft Excel Worksheet Functions 1 16th Nov 2007 06:15 PM
AVERAGEIF equivalent in excel 2000 flumpuk Microsoft Excel Misc 4 16th Oct 2007 08:46 AM
Using formulas in conditions (SUMIF, AVERAGEIF) Jan Kucera Microsoft Excel New Users 15 4th Oct 2007 05:51 AM
EXCEL -- want to do have ''averageif'' - like sumif function - H. =?Utf-8?B?R2xlbmRh?= Microsoft Excel Worksheet Functions 1 5th Apr 2005 08:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.