Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
lschuh
 
Posts: n/a
Default macro to copy and edit then delete a worksheet

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions


--

Dave Peterson
  #3   Report Post  
lschuh
 
Posts: n/a
Default

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
lschuh
 
Posts: n/a
Default

I can't get the syntax to work
curwks.copy_
befo=worksheets(1)

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
lschuh
 
Posts: n/a
Default

I spoke too soon. That line works when you type it in correctly.
Can I ask what the
..range("a1").value = "hi xxx" is supposed to do.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
lschuh
 
Posts: n/a
Default

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson

  #8   Report Post  
Dave Peterson
 
Posts: n/a
Default

You said that you needed to change something on that copied sheet. I figured
you were gonna do that via code.

I used
.range("a1").value = "Hi there"
to show you where you'd add your code that changes something.



lschuh wrote:

I spoke too soon. That line works when you type it in correctly.
Can I ask what the
.range("a1").value = "hi xxx" is supposed to do.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #9   Report Post  
Dave Peterson
 
Posts: n/a
Default

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
lschuh
 
Posts: n/a
Default

I got this to sort of do what I want by using one macro and then did my
editing. When I was done editing I invoked another macro to delete the
sheet. save, close. Cheated but what the heck. I never put the a1 "hi
there" in as all I wanted to do is delete rows I did not need just to clean
up the worksheet. I am trying to use it as a form. I am creating
audiometric (hearing) charts. All employees have more years of data then
others. I am allowing enough rows to be placeholders for years 1979 through
2005. Some employees have been at the company long enough to have data in
all the rows(26). Others will not. All the rows have referential
referencing from the worksheet (audiochart). By creating a copy of the
original (audiochart(1)) I can edit those rows not needed without wiping out
(audiochart) referencing. The referencing is coming from a
transferspreadsheet that is tied to an MSAccess macro. I hope that explains
what I was trying to do.

"Dave Peterson" wrote:

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson



  #11   Report Post  
Dave Peterson
 
Posts: n/a
Default

I never meant for you to actually put "hi there" in your real code. It was just
a place holder for the code that would do the editing.

In fact, if you could give the rules for what rows to delete, you could plop
that code into the module.

If the rules are too complex and they need a human to do it, breaking up the
macro into pieces is a perfect choice. (well, your macro could ask for the
range of rows to delete and delete them, but that's just a matter of choice.)



lschuh wrote:

I got this to sort of do what I want by using one macro and then did my
editing. When I was done editing I invoked another macro to delete the
sheet. save, close. Cheated but what the heck. I never put the a1 "hi
there" in as all I wanted to do is delete rows I did not need just to clean
up the worksheet. I am trying to use it as a form. I am creating
audiometric (hearing) charts. All employees have more years of data then
others. I am allowing enough rows to be placeholders for years 1979 through
2005. Some employees have been at the company long enough to have data in
all the rows(26). Others will not. All the rows have referential
referencing from the worksheet (audiochart). By creating a copy of the
original (audiochart(1)) I can edit those rows not needed without wiping out
(audiochart) referencing. The referencing is coming from a
transferspreadsheet that is tied to an MSAccess macro. I hope that explains
what I was trying to do.

"Dave Peterson" wrote:

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #12   Report Post  
lschuh
 
Posts: n/a
Default

so I suppose to do that you would probably need a msg box? Maybe I could do
that when I get better with coding in Excel. It doesn't look that difficult,
I think more straight forward then other programs. Thanks for all your help.


"Dave Peterson" wrote:

I never meant for you to actually put "hi there" in your real code. It was just
a place holder for the code that would do the editing.

In fact, if you could give the rules for what rows to delete, you could plop
that code into the module.

If the rules are too complex and they need a human to do it, breaking up the
macro into pieces is a perfect choice. (well, your macro could ask for the
range of rows to delete and delete them, but that's just a matter of choice.)



lschuh wrote:

I got this to sort of do what I want by using one macro and then did my
editing. When I was done editing I invoked another macro to delete the
sheet. save, close. Cheated but what the heck. I never put the a1 "hi
there" in as all I wanted to do is delete rows I did not need just to clean
up the worksheet. I am trying to use it as a form. I am creating
audiometric (hearing) charts. All employees have more years of data then
others. I am allowing enough rows to be placeholders for years 1979 through
2005. Some employees have been at the company long enough to have data in
all the rows(26). Others will not. All the rows have referential
referencing from the worksheet (audiochart). By creating a copy of the
original (audiochart(1)) I can edit those rows not needed without wiping out
(audiochart) referencing. The referencing is coming from a
transferspreadsheet that is tied to an MSAccess macro. I hope that explains
what I was trying to do.

"Dave Peterson" wrote:

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

  #13   Report Post  
Dave Peterson
 
Posts: n/a
Default

Actually, you could use application.inputbox() to get the range (msgboxes
wouldn't work if you want the user to select the rows to delete).

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet
Dim myRng As Range

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=Worksheets(1)

Set newWks = ActiveSheet

With newWks
.Activate
Set myRng = Nothing
On Error Resume Next
Set myRng = Application.InputBox _
(Prompt:="Please select some cells to indicate " & _
"what rows should be deleted", Type:=8)
On Error GoTo 0
If myRng Is Nothing Then
'user hit cancel.
Else
If myRng.Parent.Name < .Name Then
MsgBox "Please select it on the same sheet!"
Else
myRng.EntireRow.Delete
.Range("a1:b99").PrintOut preview:=True
End If
End If
'clean up that sheet

Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
End With

End Sub

lschuh wrote:

so I suppose to do that you would probably need a msg box? Maybe I could do
that when I get better with coding in Excel. It doesn't look that difficult,
I think more straight forward then other programs. Thanks for all your help.


"Dave Peterson" wrote:

I never meant for you to actually put "hi there" in your real code. It was just
a place holder for the code that would do the editing.

In fact, if you could give the rules for what rows to delete, you could plop
that code into the module.

If the rules are too complex and they need a human to do it, breaking up the
macro into pieces is a perfect choice. (well, your macro could ask for the
range of rows to delete and delete them, but that's just a matter of choice.)



lschuh wrote:

I got this to sort of do what I want by using one macro and then did my
editing. When I was done editing I invoked another macro to delete the
sheet. save, close. Cheated but what the heck. I never put the a1 "hi
there" in as all I wanted to do is delete rows I did not need just to clean
up the worksheet. I am trying to use it as a form. I am creating
audiometric (hearing) charts. All employees have more years of data then
others. I am allowing enough rows to be placeholders for years 1979 through
2005. Some employees have been at the company long enough to have data in
all the rows(26). Others will not. All the rows have referential
referencing from the worksheet (audiochart). By creating a copy of the
original (audiochart(1)) I can edit those rows not needed without wiping out
(audiochart) referencing. The referencing is coming from a
transferspreadsheet that is tied to an MSAccess macro. I hope that explains
what I was trying to do.

"Dave Peterson" wrote:

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #14   Report Post  
Dave Peterson
 
Posts: n/a
Default

ps. If you're doing more than deleting rows, I like your start, stop, and
restart solution much better.

lschuh wrote:

so I suppose to do that you would probably need a msg box? Maybe I could do
that when I get better with coding in Excel. It doesn't look that difficult,
I think more straight forward then other programs. Thanks for all your help.


"Dave Peterson" wrote:

I never meant for you to actually put "hi there" in your real code. It was just
a place holder for the code that would do the editing.

In fact, if you could give the rules for what rows to delete, you could plop
that code into the module.

If the rules are too complex and they need a human to do it, breaking up the
macro into pieces is a perfect choice. (well, your macro could ask for the
range of rows to delete and delete them, but that's just a matter of choice.)



lschuh wrote:

I got this to sort of do what I want by using one macro and then did my
editing. When I was done editing I invoked another macro to delete the
sheet. save, close. Cheated but what the heck. I never put the a1 "hi
there" in as all I wanted to do is delete rows I did not need just to clean
up the worksheet. I am trying to use it as a form. I am creating
audiometric (hearing) charts. All employees have more years of data then
others. I am allowing enough rows to be placeholders for years 1979 through
2005. Some employees have been at the company long enough to have data in
all the rows(26). Others will not. All the rows have referential
referencing from the worksheet (audiochart). By creating a copy of the
original (audiochart(1)) I can edit those rows not needed without wiping out
(audiochart) referencing. The referencing is coming from a
transferspreadsheet that is tied to an MSAccess macro. I hope that explains
what I was trying to do.

"Dave Peterson" wrote:

Actually, it copies the worksheet, changes A1 (look for that "Hi There" in the
printpreview window), then deletes the worksheet after you dismiss the
printpreview window.



lschuh wrote:

it does not copy the worksheet. it goes right to the print preview.

"Dave Peterson" wrote:

Why not just copy it to a new workbook????

but...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet 'worksheets("audioinput")

curWks.Copy _
befo=worksheets(1)

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
application.displayalerts = false
.delete
application.displayalerts = true
End With

End Sub

lschuh wrote:

I am copying a worksheet (within a workbook). Basically I am creating a copy
of an existing worksheet. (eg: "audioinput", "audioinput(1)"
The reason I want to copy the existing worksheet is so that I can edit and
make the cosmetics better before I print out a hard copy. After my print
out, I then want to delete the "audioinput(1)". I was thinking I would have
to save the worksheet but all that is necessary before closing is to remove
the extra "audioinput(1)" or the next time I run the macro I will have an
"audioinput(2)" and so on.....

"Dave Peterson" wrote:

Are you copying the worksheet to a new workbook? If yes, then you can do all
your editing, print it and just close that workbook. Since that workbook hasn't
been saved, you don't need to delete it.

Kind of...

Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim newWks As Worksheet

Set curWks = ActiveSheet

curWks.Copy 'to a new workbook

Set newWks = ActiveSheet

With newWks
.Range("a1").Value = "hi there!"
.Range("a1:b99").PrintOut preview:=True
.Parent.Close savechanges:=False
End With

End Sub

(I used preview:=true to save some paper.)



lschuh wrote:

I have created a macro that will open the workbook, print preview, copy a
worksheet. After I create the copy I want to edit the contents then print a
range. Upon exiting I want to delete the copy I created save and close the
workbook. I have been able to do everything except do the editing in the
worksheet before the macro prints, deletes and closes. Any suggestions

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
cannot copy a worksheet within a workbook ROBERT P. SANDOZ Excel Discussion (Misc queries) 3 August 16th 05 04:53 PM
HOW DO I COPY A CONDITIONAL SUM (sumif) AND EDIT IT? (THE SUM NEV. ailsa.fraser Excel Worksheet Functions 5 April 22nd 05 03:10 PM
How do I copy my dropdown box with data to another worksheet? Tess Excel Worksheet Functions 0 February 10th 05 09:33 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 01:40 AM
How do I edit, copy and paste text in excel cells? floridactyl New Users to Excel 2 December 31st 04 04:52 PM


All times are GMT +1. The time now is 11:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"