Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default CSE formulas in vba(ie: averageif in Excel 2003)

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").Ra nge("A1:B10000")
SourceRcount = sourceRange.Rows.Count
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cell s(rnum, "A")

With sourceRange
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cell s(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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default CSE formulas in vba(ie: averageif in Excel 2003)

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").Ra nge("A1:B10000")
SourceRcount = sourceRange.Rows.Count
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cell s(rnum, "A")

With sourceRange
Set destrange =
mybook.Worksheets("NetWeatherResidualLookup").Cell s(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
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
AVERAGEIF FORMULA EXCEL 2007 tcbooks Excel Discussion (Misc queries) 1 April 12th 10 08:03 PM
Is there an AVERAGEIF function in excel? lisab Excel Discussion (Misc queries) 5 November 9th 09 06:46 PM
Help with Averageif Formula (don't think I should use Averageif) MUmfleet Excel Discussion (Misc queries) 5 April 9th 09 04:53 PM
Excel AverageIF issue... PLEASE HELP! [email protected] Excel Worksheet Functions 1 November 16th 07 06:15 PM
Using formulas in conditions (SUMIF, AVERAGEIF) Jan Kucera New Users to Excel 15 October 4th 07 05:51 AM


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