473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to get the sheet name from a prompt input

I am trying to get the worksheet name from a prompt input box

The following will work the first time through but not the next. Can someone point me in the right direction

Expand|Select|Wrap|Line Numbers
  1. Sub Getsheetname()
  2.  
  3.     Dim address As String
  4.     Dim address1 As String
  5.     Dim address2 As String
  6.     Dim shtname As String
  7.  
  8.  
  9.     'Show input box to get where they want it paste
  10.     Set OutputCells = _
  11.     Application.InputBox(prompt:="Select the Range to paste the Calcs", _
  12.     Title:="Select the range to Paste the Calcs", Type:=8)
  13.     On Error GoTo 0
  14.  
  15.     If OutputCells Is Nothing Then GoTo ExitProc
  16.  
  17.     Application.ScreenUpdating = False
  18.  
  19.     'Get the Sheet name of the outputcells
  20.     address = OutputCells.address(External:=True)
  21.     address1 = Right(address, Len(address) - InStr(1, address, "]"))
  22.     address2 = Left(address1, Len(address1) - InStr(1, address1, "!"))
  23.     shtname = address2
  24.  
  25.     'Select the Sheet
  26.     Worksheets(shtname).Select
  27.     Range("A1").Select
  28.  
  29.     'check the sheet name
  30.     'Cells(1, 1) = shtname
  31.  
  32. ExitProc:
  33.  
  34.     Set OutputCells = Nothing
  35.  
  36. End Sub
  37.  
I really would appreciate any help I could get
Apr 16 '11 #1
1 1625
Looks like i figured it out...
I used
Expand|Select|Wrap|Line Numbers
  1.     'Get the Sheet name of the outputcells
  2.     shtname = OutputCells.Parent.Name
  3.  
instead or the folowing and it seems to work
Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Get the Sheet name of the outputcells
  3.     address = OutputCells.address(External:=True)
  4.     address1 = Right(address, Len(address) - InStr(1, address, "]"))
  5.     address2 = Left(address1, Len(address1) - InStr(1, address1, "!"))
  6.     shtname = address2
  7.  
Apr 16 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: isis5 | last post by:
i am using c# to parse some excel files to oracle.these files are created by an automated 3rd party process and we have no control over the naming convention and the version is excel 4.0 and the...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
1
by: sunil1026 | last post by:
Hi, This is sunil, How to create a table in procedure with table name as input parameter to procedure........
5
by: cssExp | last post by:
alright suppose i have the following. <input type="file" name="upload" /> <input type="text" name="discription" /> <input type="image" onclick="addFile();" src="images/addfile.jpg" name="add"...
1
by: prakashsakthivel | last post by:
Hi Members, Maximum size of excel sheet name is 31. is it posssible to increase excel sheet name length . Thanks & Regards musai.
4
by: =?Utf-8?B?THluZXJz?= | last post by:
Hello All, We have a VB.NET application writen using VS 2003. This application apens an excel file from a vendor, reads the data and performs whatever functions it needs. We recently upgraded our...
2
by: if1467 | last post by:
Hi, I am using VB 6.3 for excel and i have the foillowing code: Sheets.Add Sheets("Sheet1").Select Sheets("Sheet1").Name = "Results" The problem is that when I re-run the program the sheet...
1
by: sveliset | last post by:
Hi all, Pls help me to get the Excel sheet name using VB.Net Code. Thanks in advance. Regards, Sukumar V
0
by: todubhai | last post by:
I am using the following code to extract the sheet names from excel: (See attached code) private String GetExcelSheetNames(string sConnectionString) { OleDbConnection objConn...
1
by: Manesh Pawar | last post by:
Hello, I a now Porting a data from Uploaded Excel File to database. In that, I need to check "Sheet name" Of that Excel file Whether it is Sheet1 or Sheet2 or something else... Will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.