Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Asking user to set a printarea when none is defined

Here's what I came up with:

First, in a module, paste the following code:

Sub CountRange()

Dim CellCount As Integer

CellCount = Selection.Count
If CellCount <= 1 Then
UserForm1.Show
End If

End Sub

Then create a UserForm with a RefEdit control and a CommandButton (RefEdit1
and CommandButton1). Double click the command button to bring up the
default CommandButton1_Click code and paste the following between the
Private Sub and End Sub lines:

Dim SetRange As Range

MsgBox RefEdit1.Value
Range(RefEdit1.Value).Select
Set SetRange = ActiveWindow.RangeSelection
ActiveSheet.PageSetup.PrintArea = SetRange.Address

Basically the CountRange counts the number of cells selected on the
worksheet and if less than 2 cells are selected pops up the form. The form
has a RefEdit control that allows the user to select a range on the
worksheet. When the CommandButton is pressed, the variable SetRange is set
to the range selected in RefEdit then the PrintArea is set.

HTH
Mike.

--
Michael J. Malinsky


"Andy" wrote in message
...
I am trying to write a routine that asks the user to set a
print area if one has not already been set.

At the start of the routine, I have used this code;

If ActiveSheet.PageSetup.PrintArea = "" Then
Load UserForm1
UserForm1.Show
End If

However, this doesn't seem to work if a range is selected
for printing.
Is there a way to check whether "a range has been selected
and if not prompt the user to do so"?



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
Excel Message "user defined type not defined" LEELK01 Excel Discussion (Misc queries) 2 August 14th 09 07:31 AM
user defined function tom_mcd Excel Worksheet Functions 1 January 6th 09 06:23 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
User Defined Functions Jeff B Excel Worksheet Functions 1 April 27th 05 09:59 PM
User Defined Functions Frank@shell Excel Worksheet Functions 3 April 20th 05 02:41 PM


All times are GMT +1. The time now is 07:38 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"