![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 1
|
The following function should set the print area as a function of column number:
--------------------------------------------- Function setprintarea(ByVal column As Integer) As String ' Sets the print area to range "A1:colstring" Dim colstring As String colstring = Chr((column Mod 26 + 65)) & "$35" 'last or only char and row number If Int(column / 26) >= 1 Then colstring = Chr((Int(column / 26) + 64)) & colstring 'higher order colstring = "$A$1:" & "$" & colstring setprintarea = colstring 'returns range Activesheet.PageSetup.printarea = colstring End Function --------------------------------------------- The column number is converted to a string and returned for info purposes. The next line should set the print area. This works when used within a sub program locally within VBA, but not from within the function or in the sub from the worksheet. Is there a restriction on these procedures from within functions? The sub name was not found when entered into a cell, thus the function attempt. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
You can't change the environment using a function, functions only returns values. You'll have to use a Sub (Or this function and use the result in a Sub)
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|