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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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