VBA Copy range from one worksheet to another and rename new worksheet

weefatb0b

New Member
Joined
Nov 17, 2022
Messages
28
Office Version
  1. 2013
Platform
  1. Windows
Hi

Working on VBA to enable me to copy a worksheet to a new worksheet within the same Workbook. I have got to here, and it does it all fine, however rather than copy the whole worksheet I only want to Copy Columns A to I, as columns J onwards contain Control Buttons that are not required on the copy

'Sub FinanceDirectorCopy()
'Dim sh As Worksheet

'Set sh = Sheets("Position")

'sh.Copy After:=Sheets(Sheets.Count)

'If sh.Range("A1").Value <> "" Then

'ActiveSheet.Name = "Finance Director" 'sh.Range("A1").Value

'End If

'sh.Activate

'End Sub


I have tried changing If sh.Range("A1") to If sh.Range("A1:I600") and to If sh.Range("A:I") but I keep getting debug errors

A1 to I600 is all I want to copy to the new named sheet.

Any help would be appreciated?

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
VBA Code:
Sub CopyAtoI()
Dim sh As Worksheet, ws As Worksheet, rng As Range

Set sh = Sheets("Position")

With sh
Set rng = .Range("A1:I" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With
Set ws = Sheets.Add
ws.Name = sh.Range("A1").Value
rng.Copy ws.Range("A1")


End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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