Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Find last row through a macro

I have data in column A. The last row filled is row number 20
I have a formula in cell C1.

I want to detect the last filled row in column A (in this example, it
is row no.20) Once the detection is over, the vba should drag formula
in C1 till C20.

The next day I will paste some more data in column A. After running the
same macro, again the same thing should happen. Detect the NEW last row
number and drag formula from C1 till CXX (XX=NEW last row)

Can anybody help?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Find last row through a macro

If I can assume that you have no empty cells between A1 and the 'last
row'
then:-

Sub FillFormulasToLastRow()
[A1].Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
qend = ActiveCell.Row
[C1].Copy Range("C2:C" & qend)
End Sub

somethinglikeant



wrote:
I have data in column A. The last row filled is row number 20
I have a formula in cell C1.

I want to detect the last filled row in column A (in this example, it
is row no.20) Once the detection is over, the vba should drag formula
in C1 till C20.

The next day I will paste some more data in column A. After running the
same macro, again the same thing should happen. Detect the NEW last row
number and drag formula from C1 till CXX (XX=NEW last row)

Can anybody help?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Find last row through a macro

Wonderful. Thanks.

Is there anyway to track how many empty cells are there between A1 and
the last row?

somethinglikeant wrote:
If I can assume that you have no empty cells between A1 and the 'last


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Find last row through a macro

No worries, I'm getting a bit smarter with this one.
qend is now the last row, even if there are empty cells in between


Sub HowManyEmptyCells()
qend = [A65536].End(xlUp).Row
Range("A" & qend).Select: x = 0
For i = qend To 1 Step -1:
Range("A" & i).Select
If IsEmpty(ActiveCell) Then x = x + 1
Next i
MsgBox x & " Empty Cells"
End Sub

somethinglikeant

wrote:
Wonderful. Thanks.

Is there anyway to track how many empty cells are there between A1 and
the last row?

somethinglikeant wrote:
If I can assume that you have no empty cells between A1 and the 'last


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Find last row through a macro

Try this:

Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown

Explanation: Range("C1", -is what to filldown
Range("A1").End(xlDown) -is how far to filldown (End of column A)
..Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to
the right =C)

Mike F

wrote in message
ps.com...
I have data in column A. The last row filled is row number 20
I have a formula in cell C1.

I want to detect the last filled row in column A (in this example, it
is row no.20) Once the detection is over, the vba should drag formula
in C1 till C20.

The next day I will paste some more data in column A. After running the
same macro, again the same thing should happen. Detect the NEW last row
number and drag formula from C1 till CXX (XX=NEW last row)

Can anybody help?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Find last row through a macro

Super !!! Just a one liner. Will this solve the above problem? (if
there are empty cells in between A1 and last row in column A)

Mike Fogleman wrote:
Try this:

Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown

Explanation: Range("C1", -is what to filldown
Range("A1").End(xlDown) -is how far to filldown (End of column A)
.Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to
the right =C)

Mike F


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Find last row through a macro

delete the rows with empty cells first then fill down


Sub Macro1()
qend = [A65536].End(xlUp).Row
Range("A" & qend).Select:
For i = qend To 1 Step -1:
Range("A" & i).Select
If IsEmpty(ActiveCell) Then ActiveCell.EntireRow.Delete
Next i
qend = [A65536].End(xlUp).Row
Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown 'nice one
mike
End Sub


somethinglikeant



wrote:
Super !!! Just a one liner. Will this solve the above problem? (if
there are empty cells in between A1 and last row in column A)

Mike Fogleman wrote:
Try this:

Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown

Explanation: Range("C1", -is what to filldown
Range("A1").End(xlDown) -is how far to filldown (End of column A)
.Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to
the right =C)

Mike F


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Find last row through a macro

Combination of both. Great !! Thank you to both of you. Really
appreciate

somethinglikeant wrote:
delete the rows with empty cells first then fill down


Sub Macro1()
qend = [A65536].End(xlUp).Row
Range("A" & qend).Select:
For i = qend To 1 Step -1:
Range("A" & i).Select
If IsEmpty(ActiveCell) Then ActiveCell.EntireRow.Delete
Next i
qend = [A65536].End(xlUp).Row
Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown 'nice one
mike
End Sub


somethinglikeant


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Find last row through a macro

No, that also assumes no missing data in column A and will only filldown to
the row above the blank cell.
This will filldown to the last used cell in column A, but will also put the
formula opposite a blank cell.

Range("C1", Cells(Rows.Count, "A").End(xlUp)).Offset(0, 2).FillDown

Basically same explanation except now we determine how far up column A do we
want to filldown in column C.

Mike F
wrote in message
oups.com...
Super !!! Just a one liner. Will this solve the above problem? (if
there are empty cells in between A1 and last row in column A)

Mike Fogleman wrote:
Try this:

Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown

Explanation: Range("C1", -is what to filldown
Range("A1").End(xlDown) -is how far to filldown (End of column A)
.Offset(0, 2) -is which column from Range("A1") to filldown (2 columns
to
the right =C)

Mike F




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
MACRO find and Go-To Teddy-B Excel Discussion (Misc queries) 4 October 26th 09 03:20 PM
Get Macro warning, but can't find Macro Stilla Excel Worksheet Functions 1 January 20th 07 01:27 AM
change error message when no more for "find" in macro to find swyltm Excel Programming 1 January 13th 06 05:16 PM
Using Find in a macro Phil Osman Excel Discussion (Misc queries) 2 August 9th 05 02:08 AM
I need to find a macro to find data cut and paste to another colu. Rex Excel Programming 6 December 7th 04 09:22 AM


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