Run time error '1004' - Method 'Range' of object '_Global' failed

billfinn

Board Regular
Joined
Jun 7, 2018
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
I am pulling my hair out in big clumps trying to resolve this. When the macro fails and I get the error message in the Title block it highlights the following line;
Range("VERSION").FormulaR1C1 = TempVersion

I assume that I've not properly defined something but I'm wearing my Captain ADHD hat and not seeing the issue at the moment. I fixed a couple of other things but this one eludes me.
I tried to identify the specific sheet I want the info to end up in with Sheets.select ("Version Control") but no help. I've spent an hour plus digging through the web but haven't resolved the issue yet.
Any suggestions, input or brickbats gratefully received.
Thanks much!
Bill

Code:
Sub TempSave()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim TempVersion As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With


Set Sourcewb = ActiveWorkbook


'Force the file extension to remain as Excel macro enabled
FileExtStr = ".xlsm": FileFormatNum = 52


ActiveSheet.Unprotect
TempFilePath = "H:\Estimator"
TempVersion = Format(Now, "yy-mm-dd hh-mm-ss")
TempFileName = "Temp " & Range("Estimator") & " " & TempVersion
Sheets.Select ("Version Control")
Range("VERSION").FormulaR1C1 = TempVersion
ActiveSheet.Protect


With Sourcewb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
End With


MsgBox "New version saved as " & TempFilePath & TempFileName


With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Firstly your code should never have got past this line as it is wrong
Code:
Sheets.Select ("Version Control")
Secondly do you have a named range called VERSION & if so is it sheet or workbook scope?
 
Upvote 0
I finally got the rectal cranial extraction and realized RANGE was not needed and was the root of my problems. I removed all the RANGE references in the macro and rewrote the line
Code:
[COLOR=#333333]Range("VERSION").FormulaR1C1 = TempVersion[/COLOR]
to read Tempversion = ("VERSION") & FormulaR1C1. Working great now.
Thanks much for your comments.
Bill
 
Upvote 0
Glad you got it sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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
Back
Top