Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default inserting a formula with reference to a new sheet in a cell using VBA

I've quite a problem I think.
I've made a userform in which the name of a new sheet can be defined
as follows:

Dim ws As Worksheet
Set ws = Worksheets.Add
ActiveSheet.Name = postnaam.Text (postnaam is the name I've given t
the textbox in which the name of the sheet is defined by user)

Later on I want to fill in a formula in another (total calculation
sheet with a reference to the new sheet, for example:

worksheets("total sheet").range("D8").formula = "='name of th
sheet'!$D$8

The problem I now encounter is that I don't know which name the use
will use for his new sheet, so I can't make an absolute reference, ye
this is what excel needs for automatically updating the value in tha
cell.

Please help me with this problem, I can't find a solution!

tnx in advance,
Pee

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default inserting a formula with reference to a new sheet in a cell using VBA

Peer,

The solution is already in your code:

Set ws = Worksheets.Add


But you should use it this way:

Set ws = Worksheets.Add
ws.Name = postnaam.Text....

If all this code is run at the same time, you still have the name available:
worksheets("total sheet").range("D8").formula = "='" & ws.name & "'!$D$8"

HTH,
Bernie
MS Excel MVP

"Peer " wrote in message
...
I've quite a problem I think.
I've made a userform in which the name of a new sheet can be defined,
as follows:

Dim ws As Worksheet
Set ws = Worksheets.Add
ActiveSheet.Name = postnaam.Text (postnaam is the name I've given to
the textbox in which the name of the sheet is defined by user)

Later on I want to fill in a formula in another (total calculation)
sheet with a reference to the new sheet, for example:

worksheets("total sheet").range("D8").formula = "='name of the
sheet'!$D$8

The problem I now encounter is that I don't know which name the user
will use for his new sheet, so I can't make an absolute reference, yet
this is what excel needs for automatically updating the value in that
cell.

Please help me with this problem, I can't find a solution!

tnx in advance,
Peer


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default inserting a formula with reference to a new sheet in a cell using VBA

You can save the name of the sheet in a defined name

Thisworkbook.Names.Add Name:="NewSheet1", Refersto:= "=""" & postnamm.Text &
""""


Then you can use this to get the name

Dim sShName as String
sShName = Evaluate(thisWorkbook.Names(NewSheet1"))
worksheets("total sheet").Range("D8").formula = "='" & sShName & _
"'!$D$8"

--
Regards,
Tom Ogilvy




"Peer " wrote in message
...
I've quite a problem I think.
I've made a userform in which the name of a new sheet can be defined,
as follows:

Dim ws As Worksheet
Set ws = Worksheets.Add
ActiveSheet.Name = postnaam.Text (postnaam is the name I've given to
the textbox in which the name of the sheet is defined by user)

Later on I want to fill in a formula in another (total calculation)
sheet with a reference to the new sheet, for example:

worksheets("total sheet").range("D8").formula = "='name of the
sheet'!$D$8

The problem I now encounter is that I don't know which name the user
will use for his new sheet, so I can't make an absolute reference, yet
this is what excel needs for automatically updating the value in that
cell.

Please help me with this problem, I can't find a solution!

tnx in advance,
Peer


---
Message posted from http://www.ExcelForum.com/



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
Reference the same row from another sheet after inserting a new ro Brian Excel Worksheet Functions 1 April 2nd 23 12:54 PM
Reference text in a cell inside a formula to specify a sheet name navel151 Excel Worksheet Functions 5 February 20th 10 07:47 AM
Use cell value as reference to sheet in formula? bluegnu Excel Worksheet Functions 4 July 20th 06 01:33 PM
Change the work sheet name in a formula by using cell reference Neel Excel Worksheet Functions 1 June 12th 06 09:24 AM
Need formula for sheet & cell reference MPH Excel Worksheet Functions 0 January 16th 05 03:39 PM


All times are GMT +1. The time now is 01:45 AM.

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"