Simple VBA issue!! Please Help!

Leyton

New Member
Joined
May 26, 2011
Messages
13
Hi,

I'm very new to VBA and I'm trying to write a code that simply takes the data from one tab and copies it into a new tab then changes the name of the newly created tab to the value of cell C9, I'm sure this is very simple but i can't link the 2 steps and i keep getting error messages!!

Here is the code i have but it doesn't work -
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
'Change name of tab
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) = "C9" Then
If Len(Trim(Target.Value)) > 0 Then
On Error Resume Next
Me.Name = Target.Value
On Error GoTo 0
End If
End If
End Sub

Any help would be greatly appreciated!
 
Hi,

Not sure how i can post a sample, sorry first day on this site need to get used to it, i only need to copy across the range A1:AW350 (only the visible coloumns some are hidden) so where would i need to put that in your original code?

Sub Button1_Click()
Application.ScreenUpdating = False
Sheets("2012 LP calculator").Cells.SpecialCells(xlCellTypeVisible).Copy 'change sheet name as required
Sheets.Add After:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Cells.PasteSpecial xlPasteValues
.Cells.PasteSpecial xlPasteFormats
.Name = .Range("C9").Value
End With
Application.ScreenUpdating = True
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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