ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro required (https://www.excelbanter.com/excel-programming/448836-macro-required.html)

pcorcele

Macro required
 
Hi
I would like a macro that will find the first empty line under col A:
I would also like that macro to activate as soon as the Excel file is opened.
Thanks
Ian M

Auric__

Macro required
 
pcorcele wrote:

I would like a macro that will find the first empty line under col A:
I would also like that macro to activate as soon as the Excel file is
opened.


Depends on what you mean by "first empty line".

If you mean "the line under the bottom used row", put this in the workbook's
ThisWorkbook object:

Private Sub Workbook_Open()
Cells(Cells.SpecialCells(xlCellTypeLastCell).Row + 1, 1).Select
End Sub


If you mean "the first line that happens to have nothing in it", use this
instead:

Private Sub Workbook_Open()
For x = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
For y = 1 To Cells.SpecialCells(xlCellTypeLastCell).Column
If Len(Cells(x, y).Formula) Then GoTo notEmpty
Next
'this is what we want
Cells(x, 1).Select
Exit Sub
notEmpty:
Next
Cells(Cells.SpecialCells(xlCellTypeLastCell).Row + 1, 1).Select
End Sub


If you mean *anything else*, you'll need to clarify.

--
I think we've found Satan's toilet.

GS[_2_]

Macro required
 
Try...

Cells(Rows.Count, 1).End(xlUp)(2).Select

...in Workbook_Open event or Auto_Open sub. Note that this will select
A2 if colA is empty. Otherwise, if A19 is the last non-empty cell in
colA then A20 will be selected.

If you want the first empty cell in colA below the first row...

Cells(1,1).End(xldown)(2).Select

...which assumes A1 is not empty, but there are some blank cells between
A1 and the last non-empty row in colA.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




All times are GMT +1. The time now is 05:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com