Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refer to a sheet in a cell

Hi

I am trying to refer to a sheet in a cell.
If the sheet does not exist, the macro will make it. Else it jus
select it.
The first part works, but i cant make it select the new sheet.

My code:

Sub Makro1()

receptnr = Sheets("Main").Range("b1")

If Not SheetExists(Sheets("Main").Range("b1")) Then
Sheets.Add
ActiveSheet.Name = receptnr
Sheets(receptnr).Select ' <-- that line causes the problem
Else
Sheets(receptnr).Select ' <-- and that one.
End If

End Sub

---

I am not very good at programming, so i may have to do this al
different. ;)

Esbe

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refer to a sheet in a cell

I have revised your code.

'-------------------------------------------
Sub Makro1()
Dim receptnr As Range
On Error GoTo MakeSheet
'- next line produces an error if sheet does not exist
Set receptnr = Sheets("Main").Range("b1")
Application.Goto reference:=receptnr
Exit Sub
'------------
MakeSheet:
Sheets.Add
ActiveSheet.Name = "Main"
Resume
End Sub
'-----------------------------------------

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refer to a sheet in a cell

hmm, that just selects the cell B2 in Main sheet.

What I want is to make a new sheet with the name written in B2 an
change to that.

If a sheet with the name written in cell B2 already exists, i just wan
to change to that sheet

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refer to a sheet in a cell

<<hmm, that just selects the cell B2 in Main sheet.
But if sheet "Main" does not exist, it will make it. So what you really
want is :-

'-------------------------------------------
Sub Makro1()
Dim receptnr As Range
Dim SheetName As String
'-------------------------------
SheetName = Sheets("Main").Range("b1").Value
On Error GoTo MakeSheet
'- next line produces an error if sheet does not exist
Set receptnr = Sheets(SheetName).Range("b1")
Application.Goto reference:=receptnr
Exit Sub
'------------
MakeSheet:
Sheets.Add
ActiveSheet.Name = SheetName
Resume
End Sub
'------------------------------------------


---
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
Cell in new sheet should always refer to defined cell in another s Ronnie Excel Discussion (Misc queries) 8 October 5th 09 02:31 PM
Refer to a sheet using a cell value bony_tony Excel Worksheet Functions 2 July 11th 08 04:27 PM
copying sheet references that refer to a cell in the preceding she GBT Excel Worksheet Functions 1 March 24th 06 07:51 PM
Set up a formala to refer to a cell in a different sheet Brian Excel Worksheet Functions 4 October 20th 05 11:51 PM
Refer to sheet name specified in other cell Marko Pinteric Excel Discussion (Misc queries) 2 March 4th 05 09:13 AM


All times are GMT +1. The time now is 07:55 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"