Automate worksheet name VBA

Utterly Bamboozled

New Member
Joined
Jul 7, 2010
Messages
39
Hi, could someone help me out in understanding why the below code doesn't work please?

Sub Export()
'
' Sheets("Timesheet").Copy Before:=Sheets(5)
ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value

On Error Resume Next
ActiveSheet.Name = Range("C6").Text
On Error GoTo 0

If ActiveSheet.Name <> Range("C6").Text Then MsgBox "Couldn't rename the sheet as " & Range("C6").Text

ActiveSheet.Range("C6:E6").Select
End Sub

I get a runtime error 1004 - Application defined or Object defined error. When I debug it highlights ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value

Thanks for your help.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
That line is supposed to paste the values of the other sheet.

Basically what I'm trying to do is create a copy of 'Timesheet'!, rename it using C6 (if possible), maintain the formatting but paste only the values. I will then export this sheet to a different model.

It was actually suggested by AlphaFrog but I can't seem to get in touch. Any assistance would be appreciated.

Regards, UB
 
Upvote 0
Something like this code may get you past the current problem. Sheet3 is the source sheet here and ActiveSheet is the target.

Dim FirstRow As Long
Dim FirstCol As Long

With Sheet3.UsedRange
FirstRow = .Rows(1).Row
FirstCol = .Columns(1).Column
.Copy
End With

ActiveSheet.Cells(FirstRow, FirstCol).PasteSpecial Paste:=xlValues

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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