Connecting Tech Pros Worldwide Forums | Help | Site Map

VBA Macro in Excel

Newbie
 
Join Date: Nov 2006
Posts: 18
#1: Jun 11 '09
I am working on a VBA macro in Excel that will copy a sheet move it and then rename it based on what the user enters in a pop up box. Here is my code for the module:

frmShow.Show

Sheets("Jun 09 New").Select
Sheets("Jun 09 New").Copy Before:=Sheets(frmShow.txtCopySheet.Text)
Sheets("Jun 09 New (2)").Select
Sheets("Jun 09 New (2)").Move After:=Sheets(frmShow.txtCopySheet.Text)
Sheets("Jun 09 New (2)").Select
Sheets("Jun 09 New (2)").Name = frmShow.txtNewSheet.Text
Columns("I:I").Select
Selection.Copy
Columns("H:H").Select
Selection.Insert Shift:=xlToRight
Columns("J:J").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("J1").Select
Selection.NumberFormat = "@"
Range("J1").Select
ActiveCell.FormulaR1C1 = frmShow.txtNewSheet.Text
Range("J2").Select




Where it has Sheets("Jun 09 New") is there a way to put the text property of a text box like I have on this line of code Sheets("Jun 09 New").Copy Before:=Sheets(frmShow.txtCopySheet.Text). It works as is, but I want to be able to have the user select a sheet to copy, then place it after that and name it the Name they put in the text box.

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,270
#2: Jun 17 '09

re: VBA Macro in Excel


Quote:

Originally Posted by mmurphmsu View Post

I am working on a VBA macro in Excel that will copy a sheet move it and then rename it based on what the user enters in a pop up box. Here is my code for the module:

Expand|Select|Wrap|Line Numbers
  1.  
  2. frmShow.Show
  3.  
  4.     Sheets("Jun 09 New").Select
  5.     Sheets("Jun 09 New").Copy Before:=Sheets(frmShow.txtCopySheet.Text)
  6.     Sheets("Jun 09 New (2)").Select
  7.     Sheets("Jun 09 New (2)").Move After:=Sheets(frmShow.txtCopySheet.Text)
  8.     Sheets("Jun 09 New (2)").Select
  9.     Sheets("Jun 09 New (2)").Name = frmShow.txtNewSheet.Text
  10.     Columns("I:I").Select
  11.     Selection.Copy
  12.     Columns("H:H").Select
  13.     Selection.Insert Shift:=xlToRight
  14.     Columns("J:J").Select
  15.     Application.CutCopyMode = False
  16.     Selection.ClearContents
  17.     Range("J1").Select
  18.     Selection.NumberFormat = "@"
  19.     Range("J1").Select
  20.     ActiveCell.FormulaR1C1 = frmShow.txtNewSheet.Text
  21.     Range("J2").Select
  22.  
  23.  
  24.  
Where it has Sheets("Jun 09 New") is there a way to put the text property of a text box like I have on this line of code Sheets("Jun 09 New").Copy Before:=Sheets(frmShow.txtCopySheet.Text). It works as is, but I want to be able to have the user select a sheet to copy, then place it after that and name it the Name they put in the text box.

Looks like nice work partner, I'll send over to VBA for added input for ya... Hope you get what you're looking for.

Good luck!
Reply