Run Time Error 438

Prevost

Board Regular
Joined
Jan 23, 2014
Messages
198
Hi There. I have found lots of discussion revolving around this error, but I did not see a solution or I am not understanding fully the nature of this issue. I am trying to open up all the Excel files in a folder and perform the same set of actions on them. It is fine until I hit the row that is commented ERROR. Any help is greatly appreciated! I am using Excel 2013 for Windows 7. Thanks in advance!

Code:
Sub Test2()

    'Workbooks.Open Filename:="C:\Temp\Book1.xlsx" - did not work...
    'ActiveWindow.Visible = False
    Application.ScreenUpdating = False

 Dim MyFolder As String
 Dim myfile As String
 Dim folderName As String
 Dim WBOpen As Workbook

 With Application.FileDialog(msoFileDialogFolderPicker)
 .AllowMultiSelect = False
 If .Show = -1 Then

 folderName = .SelectedItems(1)
 End If
 End With

 myfile = Dir(folderName & "\*.xlsx")

 Do While myfile <> ""
 Workbooks.Open FileName:=folderName & "\" & myfile
 
    'With ActiveWorkbook
    
    Dim i As Long: i = 2
    Dim PF, Voltage
    
    'PF = InputBox("Enter Power Factor")
    'Voltage = InputBox("Enter Line to Neutral Voltage")
    ActiveWorkbook.Cells(1, 14) = "Power Factor"         'ERROR
    ActiveWorkbook.Cells(1, 15) = 0.9
    ActiveWorkbook.Cells(2, 14) = "L2N Voltage"
    ActiveWorkbook.Cells(2, 15) = 347
    
    ActiveWorkbook.Cells(1, 13) = "Power (kW)"
    
        Do While ActiveWorkbook.Cells(i, 12) <> vbNullString
            ActiveWorkbook.Cells(i, 13) = "=(RC[-9]+RC[-5]+RC[-1])*60/1000*R1C15*(R2C15/347)"
            i = i + 1
        Loop
    ActiveWorkbook.Save
'use below 3 lines if you want to close the workbook right after saving, so you dont have a lots of workbooks opened
 Application.DisplayAlerts = False
 ActiveWorkbook.Close
 Application.DisplayAlerts = True
 myfile = Dir
 
 'End With
 
 Loop
 
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Cells is a property of a SHEET, not a BOOK.

So this
ActiveWorkbook.Cells(1, 14) = "Power Factor"
Would have to include a reference to a specific sheet in that book
Like
ActiveWorkbook.Sheets("SheetName").Cells(1, 14) = "Power Factor"

You could perhaps just change it to ActiveSheet
ActiveSheet.Cells(1, 14) = "Power Factor"
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,576
Messages
5,765,196
Members
425,266
Latest member
CPAgirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top