Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need Code For Selection

Hello
I hope someone will help me to solve my problem.
I have the data from column A to G (from H.. everything is blank) and
keep adding data below it. Is there any way I can run a macro to selec
the print area by finding the last row? Eg: if I have data in 16 row
and when I run the macro it should select the range A1-G16 and set th
print area. Row 17 will have no data in it.
Hope it is clear.
Thanks in Advance
Regds
Tom

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Need Code For Selection


-----Original Message-----
Hello
I hope someone will help me to solve my problem.
I have the data from column A to G (from H.. everything

is blank) and I
keep adding data below it. Is there any way I can run a

macro to select
the print area by finding the last row? Eg: if I have

data in 16 rows
and when I run the macro it should select the range A1-

G16 and set the
print area. Row 17 will have no data in it.
Hope it is clear.
Thanks in Advance


Try this
Sub LastNonBlankCell()
'Finds the last cell in a worksheet with an entry
(discounts formats & borders).
'Routine is very fast because it does NOT select/activate
each column or row.
Dim CurrCol As Long, CurrRow As Long
Dim Add As String

'This finds where Excel thinks the last cell is.
Add = Selection.SpecialCells(xlCellTypeLastCell).Address
'It either really is the last cell or the last cell is
inside it.
CurrCol = Range(Add).Column
CurrRow = Range(Add).Row

'TEST THE COLUMNS
'Test to see if this column is blank
CurrCol = CurrCol + 1 'ie the column one to the right
Do 'test in turn the columns to the left
CurrCol = CurrCol - 1
Loop Until Application.WorksheetFunction.counta(Columns
(CurrCol)) 0
'CurrCol is now the column with the last data in it.

'TEST THE ROWS
'now test to see if this row is blank
CurrRow = CurrRow + 1 'ie one row lower
Do 'test in turn the rows above
CurrRow = CurrRow - 1
Loop Until Application.WorksheetFunction.counta(Rows
(CurrRow)) 0
'CurrRow is now the row with the last data in it.

'position the 'last' cell
Cells(CurrRow, CurrCol).Activate

End Sub
Regds
Toms


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Need Code For Selection

Hello Toms
Please amend accordingly:
With Worksheets("Sheet1")
..PageSetup.PrintArea = .Range("A1").CurrentRegion.Address
End With

"SMILE " a écrit dans le message de
...
Hello
I hope someone will help me to solve my problem.
I have the data from column A to G (from H.. everything is blank) and I
keep adding data below it. Is there any way I can run a macro to select
the print area by finding the last row? Eg: if I have data in 16 rows
and when I run the macro it should select the range A1-G16 and set the
print area. Row 17 will have no data in it.
Hope it is clear.
Thanks in Advance
Regds
Toms


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Need Code For Selection

here is some code i use to set the print area

Range("A1").select
ActiveWorkbook.Names.Add Name:="Top50Rpt", RefersTo:= _
Range(Range("A1"),Range("A1").Offset(49,15))
ActiveSheet.PageSetup.PrintArea = "Top50Rpt"

You might have to change the code a little to something
like:
RefersTo:=Range(Range("A1"),Range("A1").end(xldown )_
..end(xltoright)

-----Original Message-----
Hello
I hope someone will help me to solve my problem.
I have the data from column A to G (from H.. everything

is blank) and I
keep adding data below it. Is there any way I can run a

macro to select
the print area by finding the last row? Eg: if I have

data in 16 rows
and when I run the macro it should select the range A1-

G16 and set the
print area. Row 17 will have no data in it.
Hope it is clear.
Thanks in Advance
Regds
Toms


---
Message posted from http://www.ExcelForum.com/

.

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
cell selection code NDBC Excel Discussion (Misc queries) 6 August 11th 09 06:39 AM
Selection code sixfivebeastman Excel Programming 3 May 27th 04 08:54 PM
Code is dragging selection when should copy rglasunow[_16_] Excel Programming 1 February 3rd 04 04:41 PM
Range selection code in a macro Floss Excel Programming 1 December 30th 03 01:05 AM
Print Selection in Code Donna Brooks Excel Programming 2 July 25th 03 04:35 PM


All times are GMT +1. The time now is 10:55 PM.

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

About Us

"It's about Microsoft Excel"