Copy pages, delete certain values

Z

zinzah

Hi. Trying to create a multiple page workbook. Start with 3 pages. Page
2 and 3 have data that does not change and is used by page 1 wit
VLOOKUP. I have been successful in adding a command button called "Ne
Page" to copy page 1 and insert it before page 2 in the workbook, bu
when trying to deleted the values in 3 different ranges ( Range1
Range2 and Range3) that were entered in page 1 before the COPY too
place, I am consistently gettng a error, or the command button seems t
work fine, but the data in the ranges are not deleted. After deletion
would like to make Cell A11 active.

Also looking to try making a second command button that will save th
file as a name that is pulled from Cell A3 and Cell A7 and print al
pages with the exception of the original pages 2 and
 
F

Frank Kabel

Hi
you may post your current code which is used after clicking the command
buttons. always easier to find your errors :)
 
Z

zinzah

This is the error I get when running the command button.

Runtime error ‘1004’
Select method of range class failed

The part after the second comment about the ranges works fine when ru
as a separate macro, but when included in the command button I get th
error

Private Sub NewPage_Click()

' Copy page and move it to next page

Dim Wks As Worksheet
Dim iCount As Integer

iCount = Worksheets.Count
Worksheets(iCount - 2).Copy after:=Worksheets(iCount - 2)
iCount = iCount + 1
Set Wks = Worksheets(iCount)
Worksheets(iCount - 2).Name = (iCount - 2)

' Delete Values for Game, Book and Quantity
Range("A11:E11").Select
Selection.ClearContents
Range("G11:M11").Select
Selection.ClearContents
Range("O11:R11").Select
Selection.ClearContents

Range("A11:E11").Select
Selection.Activate



End Su
 
F

Frank Kabel

Hi
you may add the worksheet references to your code. Currently you only
use
Range(...)

try something like
with worksheets("your_sheet")
.range(....)
'...
end with

or use an object variable like your 'wks' for this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top