Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default sheet name as variable

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).Ra nge("A10")
End Sub

Thanks a lot.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default sheet name as variable

It gives error at the

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

line but I couldn't manage. thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default sheet name as variable

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
'<<=============


---
Regards,
Norman


"oercim" wrote in message
ups.com...
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).Ra nge("A10")
End Sub

Thanks a lot.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default sheet name as variable

Hello Norman, It gives error in line

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

Thanks alot.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default sheet name as variable

Hello Norman, It gives error in line

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

Thanks alot.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default sheet name as variable

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?

In article . com,
"oercim" wrote:

Hello Norman, It gives error in line

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default sheet name as variable

Sorry, it worked. Thank u very much. Cheers

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add sheet name into a variable. Richhall[_2_] Excel Worksheet Functions 1 September 18th 09 12:11 PM
How To make a sheet reference Variable (eq: sum(sheet!D2:H2)) John Linker Excel Discussion (Misc queries) 3 June 16th 08 11:29 PM
Variable sheet and Formula Sheet Emmett423 Excel Discussion (Misc queries) 2 March 31st 06 02:14 AM
Sheet Name as a Variable? Petitboeuf[_5_] Excel Programming 2 December 21st 05 03:58 PM
variable in a link where the variable is the name of the sheet darrelly Excel Worksheet Functions 1 October 7th 05 08:24 AM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"