473,387 Members | 1,925 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,387 software developers and data experts.

Excel:create new worksheet from userform & enter text box entry

Hi
I have been searching through post but i didnt find any.
I would like to be able to add txt box entry to new sheet . I will appreciate if someone help me .


Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.  
  3.  Dim ActiveSheetNumber As String
  4.  
  5.     ActiveSheetNumber = SquadronMissionNumber
  6.     NewSheetName = "Mission " + ActiveSheetNumber
  7.  
  8.     Sheets.Add After:=Sheets(Sheets.Count)
  9.     ActiveSheet.Name = NewSheetName
  10.  
  11. End Sub
  12.  
  13. Private Sub TextBox1_Change()
  14.  Sheets.Add After.Range("a2") = TextBox1.Value
  15. End Sub
Aug 8 '10 #1

✓ answered by Stewart Ross

It is not clear what you are wanting to do from what little you tell us. If it is to place the value in textbox1 into cell A2 of the new activesheet it is incorrect to use the Add method of the Worksheet object.

In line 14 above refer instead to the activesheet itself:

Expand|Select|Wrap|Line Numbers
  1. Activesheet.Range("A2") = Textbox1
-Stewart

4 5891
Stewart Ross
2,545 Expert Mod 2GB
It is not clear what you are wanting to do from what little you tell us. If it is to place the value in textbox1 into cell A2 of the new activesheet it is incorrect to use the Add method of the Worksheet object.

In line 14 above refer instead to the activesheet itself:

Expand|Select|Wrap|Line Numbers
  1. Activesheet.Range("A2") = Textbox1
-Stewart
Aug 8 '10 #2
Thank you so much for reply.what I am trying to do
is when I click on command button it saves the textbox value in a new sheet and name the sheet as day1 day2 day 3 so on .since it not correct if you let me know if it is possivle to do anyother way .thank you again.
Aug 8 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. I don't know enough about your application to be able to give a detailed response to you on creating separate sheets labelled Day 1, Day 2 and so on. This I must leave to you.

I have listed below a variation on the sub you already had in your post to give some ideas - but this is likely to start at Day 4 or similar (as usually there is more than one worksheet already created in a new workbook, so the worksheet count is greater than one). The value from the textbox is copied as the last step (line 6).

I notice that you cannot be using the compiler command Option Explicit, which you should have at the top of your code module. It will guard you against undeclared variables such as NewSheetName and SquadronMissionNumber that are included in your sample code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click() 
  2.   Dim NewSheetName as String
  3.   NewSheetName = "Day Sheet " & Worksheets.Count
  4.   Sheets.Add After:=Worksheets(Worksheets.Count) 
  5.   ActiveSheet.Name = NewSheetName 
  6.   Activesheet.Range("A2") = Textbox1 
  7. End Sub
-Stewart
Aug 9 '10 #4
So impressive, it works just as I wanted. Thank you so much.Thank you again.
Aug 10 '10 #5

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

Similar topics

2
by: James | last post by:
Hi, I am using the following code to protect the active worksheet: Excel.Worksheet activeWorkSheet = (Excel.Worksheet) excelApp.ActiveWorkbook.ActiveSheet; ...
0
by: Narshe | last post by:
I'm using the excel object from office web components in an asp.net webpage. I have 2 major issues. When a user hits enter on a cell, it moves cells. That's fine, 'cause that's how excel...
0
by: suryar | last post by:
Hi please help me some one in my company i want to write a script in vb to write a text file but the source file is an excel file i want write a text or dat file with fixed lengths maping with ...
0
by: kennedystephen | last post by:
This seems like a simple task. But it's kicking my butt. I have 1 existing excel file. I want to copy the first 50 rows from that excel file, and put them in a new excel file. Then I want to get...
7
by: shantanu | last post by:
Hi all i am trying to save a excel file as a tab delimited text file. can i do it some how? i using the code _sheet1.SaveAs(@"C:\PRP \PRPTemp.txt",Excel.XlFileFormat.xlTextWindows...
0
by: tejendra | last post by:
I Have Problem While Droping Column From Excel Table Using Oledb Connection By Using Microsoft Jet Provider I Use Following Code Alter Tablename Drop Columnname Code Runs Successfully But It...
1
by: brenty66 | last post by:
I have a userform that is used as an interface for information stored on excel spreadsheets. The user enters bits of information into fields on the userform which are place on the corresponding...
5
kadghar
by: kadghar | last post by:
Most of the times VBA is used with variables. Objects (such as worksheets, cells or databases) are only used when we read their properties (value, formula, font...) or we use a method (save,...
7
by: vbanewbie2 | last post by:
is there a a way to get from excel spreedsheet to userform? anybody? please
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.