Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-15-2012, 04:37 AM
ibrahimaa ibrahimaa is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2007
Advanced Beginner
Create/delete New worksheet
 
Join Date: May 2011
Posts: 35
ibrahimaa is on a distinguished road
Default Create/delete New worksheet

I have tested code to create new workbook and it worked fine. How can I edit the following code to create & delete a new worksheet? I appreciate your support. Thank you.



Code:
Sub getvalue()
Dim Path, Myrange, ShName, Wb As String
Path = "\\ABC"
Wb = "Report-1c-Server.xlsx"
Myrange = "A9:C9700" 
Workbooks.Open Filename:=Path & "\" & Wb
 With ThisWorkbook.Sheets("EXHIBIT 6-A") 
 .Activate
Select Case ThisWorkbook.Sheets("EXHIBIT 6-A").Cells(6, "G")
Case 7
I want Create a new worksheet here 
ShName = "Aramco-MP-July"
ActiveSheet.Cells(9, "A") = Application.VLookup(ActiveSheet.Cells(5, "J"), Workbooks(Wb).Sheets(ShName).Range(Myrange), 3, False)
Case 8
ShName = Sheets("Aramco-MP-Aug")
ActiveSheet.Cells(21, "A") = Application.VLookup(ActiveSheet.Cells(9, "J"), Workbooks(Wb).Sheets(ShName).Range(Myrange), 5, False)
I want delete a new worksheet here 
Case Else
End Select
End With
Workbooks(Wb).Close , savechanges = True
End Sub  
Reply With Quote
  #2  
Old 01-15-2012, 08:43 AM
Catalin.B Catalin.B is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

add this line:
Code:
ThisWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
or:
Code:
Worksheets.Add().Name = "MySheet"
or, if you want to add more than 1 sheet, use:
Code:
Worksheets.Add After:=Worksheets(Worksheets.Count), Count:=4
to delete a sheet use:
Sheets("Sheet1").delete
or:
ActiveSheet.delete
Make sure to turn off events if you do not want to see the confirmation pop-up message: (change back to true after you delete the sheet)
Code:
Application.DisplayAlerts = False
Reply With Quote
  #3  
Old 01-16-2012, 10:08 PM
ibrahimaa ibrahimaa is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2007
Advanced Beginner
Create/delete New worksheet
 
Join Date: May 2011
Posts: 35
ibrahimaa is on a distinguished road
Wink

Thank a lot for the great support. It worked fine; however, I should create the new sheet to present specific details for specific users (60 users out of 200 users that will use the form on a corporate level).

I am planning to read the user Id from the system registry file to control this issue in the form. Any idea about reading the user ID would be highly appreciated. Thank you.
Reply With Quote
  #4  
Old 01-16-2012, 11:43 PM
Catalin.B Catalin.B is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

To get the user name, just use
User=Environ("USERNAME")
Reply With Quote
  #5  
Old 01-16-2012, 11:51 PM
ibrahimaa ibrahimaa is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2007
Advanced Beginner
Create/delete New worksheet
 
Join Date: May 2011
Posts: 35
ibrahimaa is on a distinguished road
Default

I highly appreciate your support. Thank you.
Reply With Quote
  #6  
Old 01-16-2012, 11:53 PM
Catalin.B Catalin.B is offline Create/delete New worksheet Windows Vista Create/delete New worksheet Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Glad to help
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete option greyed out when trying to delete row 1 tpcervelo Excel 2 11-15-2011 06:48 AM
Create/delete New worksheet How to delete page not worksheet? rec Excel 6 05-20-2011 08:51 PM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
Create/delete New worksheet Can I use a formula to name a worksheet? nolesca Excel 3 06-07-2010 04:02 PM
Create/delete New worksheet Worksheet copying? markg2 Excel 4 01-07-2010 10:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft