Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2005, 06:52 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Determine Last Cells Containing Data

' Determine Last Cells (row & column number) Containing Data
' Calculates the Last Cells containing Data in the Worksheet
'
Code:
Public Sub LastCellsWithData()
'   ExcelLastCell is what Excel thinks is the last cell
Set ExcelLastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)

'   Determine the last row with data in it  (must also copy above para for this to work)
LastRowWithData = ExcelLastCell.Row
Row = ExcelLastCell.Row
Do While Application.CountA(ActiveSheet.Rows(Row)) = 0 And Row <> 1
    Row = Row - 1
Loop
LastRowWithData = Row          ' Row number

'   Determine the last column with data in it  (must also copy the top para for this to work)
LastColWithData = ExcelLastCell.Column
Col = ExcelLastCell.Column
Do While Application.CountA(ActiveSheet.Columns(Col)) = 0 And Col <> 1
    Col = Col - 1
Loop
LastColWithData = Col       ' Column number
End Sub

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
1 userform: txtbox data sent to cells in workbk on Bafa VB Databases Basics 5 July 18th, 2008 12:57 PM
Copy specific data in specific cells of sheet2 yogeshyl Excel VBA 1 May 14th, 2007 07:40 AM
how to determine if there is existing data knightneo PHP Databases 2 December 3rd, 2006 01:35 AM
Determine the number of data rows in a sheet ashu_gupta75 Excel VBA 1 July 31st, 2004 03:10 PM
Entering data to dynamic table cells weebadbilly XSLT 0 June 30th, 2004 07:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.