sheet name as variable

  • Thread starter Thread starter oercim
  • Start date Start date
O

oercim

Hello. In excel macro, I want to make below statements:

1. adding a sheet whose name is a variable( name is taken
from the the cell:sheet1,A1)
2. pasting some rows from another sheet to added sheet.
I made the below code, but it doesn't work

Sub d()
Dim sht As Worksheet

Set sht = Sheets("sheet1").Range("A1").Value

Sheets("sheet2").Rows("10:20").Copy.Sheets(sht).Range("A10")
End Sub

Thanks a lot.
 
It gives error at the

"Set sht = Sheets("sheet1").Range("A1").Value"

line but I couldn't manage. thanks.
 
Hi Oercim,

Try this adaptation:

'=============>>
Sub d()
Dim sht As Worksheet

Set sht = Worksheets.Add
sht.Name = Sheets("sheet1").Range("A1").Value

Sheets("sheet2").Rows("10:20").Copy Destination:=sht.Range("A10")
End Sub
'<<=============
 
Hello Norman, It gives error in line

"sht.Name = Sheets("sheet1").Range("A1").Value"

Thanks alot.
 
Hello Norman, It gives error in line

"sht.Name = Sheets("sheet1").Range("A1").Value"

Thanks alot.
 
What error is it giving?

Is Sheet1 the name of the reference sheet?

Is the value in A1 a valid name?

Do you already have a sheet with the name in A1?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top