Copy Sheet Name

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi,

How could I write a macro code that would copy the sheet name to the sheet "Mysheet"'s cell A1 and activate the sheet "MySheet".

Any help on this would be kindly appreciated.

Thanks in advance.
 

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
Thanks for the help.

The following code copies the value from column 4 and pastes the value to Mysheet's cell O6.

How could I make the code to copy the value from the active sheet and paste the value in O6 of the sheet's name value in A1 of the active sheet.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False
If Target.Column = 4 Then
Cancel = True
Target.Copy
Sheets("MySheet").Range("O6").PasteSpecial Paste:=xlPasteValues
Worksheets("MySheet").Activate
End If
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Instead of :-

Code:
Sheets("MySheet").Range("O6").PasteSpecial Paste:=xlPasteValues

Try :-

Code:
Sheets([A1]).Range("O6").PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Well I'm getting a debug message with highlighting the line you had suggested.

what may be the reason for this?
 
Upvote 0
It doesnt work either way. Here is the code
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False
If Target.Column = 4 Then
Target.Copy
Sheets(Range("A1").Value).Range("O6").PasteSpecial Paste:=xlPasteValues
Sheets(Range("A1").Value).Activate
End If
Application.CutCopyMode = False
Sheets("MySheet").Range("A1").ClearContents
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Change to :-

Code:
Sheets(Range("A1").Value).Activate
Sheets(Range("A1").Value).Range("O6").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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