Whats wrong with this macro please

G

Guest

Hi
All i want to do is press a form button and print out a cell range, there
are multiple buttons on the spreadsheet each on to print a different range of
cells on same sheet i used this "ActiveSheet.PrintOut.PageSetup.PrintArea =
"A8:B8" to try and doi it changing the print area but it keeps saying there
is an error, any ideas anybody please, or is there another way to do it
 
T

Trevor Shuttleworth

Mike

try:

With ActiveSheet
.PageSetup.PrintArea = "A8:B8"
.PrintPreview
' .PrintOut
End With

Regards

Trevor
 
D

Dave Peterson

You could use something like:

With ActiveSheet
.PageSetup.PrintArea = "a8:b8"
.PrintOut preview:=True
End With

Or maybe without changing the printrange...

ActiveSheet.Range("a8:b8").PrintOut preview:=True
 
G

Guest

Thanks Dave
That works brilliantly, is there a way to record how many times the button
is pressed as well please
--
thanks


Dave Peterson said:
You could use something like:

With ActiveSheet
.PageSetup.PrintArea = "a8:b8"
.PrintOut preview:=True
End With

Or maybe without changing the printrange...

ActiveSheet.Range("a8:b8").PrintOut preview:=True
 
J

Jim May

Keep in mind that the cell reference A8:b8 will not change (in your code
module) if in the excel sheet (interface) "someone" moves your range or
inserts a row or column; Giving A8:B8 a name would improve such things.

HTH
 
D

Dave Peterson

You could use a cell in a worksheet (that's hidden).

ActiveSheet.Range("a8:b8").PrintOut preview:=True
with worksheets("hiddennamehere").range("a1")
if isnumeric(.value) then
.value = .value + 1
else
.value = 1
end if
end with

But if you use this kind of thing, then you have to save the workbook -- so that
the counter gets saved for the next time.

And it's not always a good thing to just save a workbook without knowing the
other changes that have been made. Is there a real reason to care?
Thanks Dave
That works brilliantly, is there a way to record how many times the button
is pressed as well please
 

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