Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Row find Macro

Hi

I'm trying to write some code so as that I can copy the last row in a sheet.
Each day a new row is added so I need it to find the new row each day. I have
written the below however although it keeps copying row 46 and not the last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Row find Macro

Try it this way...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Selection.Copy
....etc...

--
Rick (MVP - Excel)


"James" wrote in message
...
Hi

I'm trying to write some code so as that I can copy the last row in a
sheet.
Each day a new row is added so I need it to find the new row each day. I
have
written the below however although it keeps copying row 46 and not the
last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Row find Macro

I just remembered, you wanted to copy columns B to M. Use this code instead
of what I posted...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Selection.Offset(0, 1).Resize(1, 12).Copy

or you could do it this way if you wanted to see the column letters...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Intersect(ActiveCell.EntireRow, Range("B:M")).Copy

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Try it this way...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Selection.Copy
...etc...

--
Rick (MVP - Excel)


"James" wrote in message
...
Hi

I'm trying to write some code so as that I can copy the last row in a
sheet.
Each day a new row is added so I need it to find the new row each day. I
have
written the below however although it keeps copying row 46 and not the
last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Row find Macro

Hi Rick

Many thanks for this I tried it with the column letters and it seemed to
work. One more question of you don't mind I am now trying to paste the data
into another sheet and thought this was ok but seems not! I tried:

Sheets("Sheet2").Select
Cells(Rows.Count, "C").End(xlUp).Select
Intersect(ActiveCell.EntireRow, Range("F:Q")).Paste


I used "C" as this is where the last line of data shows and F:Q as this is
where I want to paste it but doesn't seem to work?



--
James.


"Rick Rothstein" wrote:

I just remembered, you wanted to copy columns B to M. Use this code instead
of what I posted...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Selection.Offset(0, 1).Resize(1, 12).Copy

or you could do it this way if you wanted to see the column letters...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Intersect(ActiveCell.EntireRow, Range("B:M")).Copy

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Try it this way...

Sheets("Sheet1").Select
Cells(Rows.Count, "A").End(xlUp).Select
Selection.Copy
...etc...

--
Rick (MVP - Excel)


"James" wrote in message
...
Hi

I'm trying to write some code so as that I can copy the last row in a
sheet.
Each day a new row is added so I need it to find the new row each day. I
have
written the below however although it keeps copying row 46 and not the
last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Row find Macro

Hi,

LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("A1:A" & LastRow).Copy Destination:=Range("B46")

Mike

"James" wrote:

Hi

I'm trying to write some code so as that I can copy the last row in a sheet.
Each day a new row is added so I need it to find the new row each day. I have
written the below however although it keeps copying row 46 and not the last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Row find Macro

Maybe I misread your post, try this

LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow).Copy Destination:=Range("B46")

Mike

"James" wrote:

Hi

I'm trying to write some code so as that I can copy the last row in a sheet.
Each day a new row is added so I need it to find the new row each day. I have
written the below however although it keeps copying row 46 and not the last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy


--
James.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Row find Macro

On Nov 13, 12:30*pm, James wrote:
Hi

I'm trying to write some code so as that I can copy the last row in a sheet.
Each day a new row is added so I need it to find the new row each day. I have
written the below however although it keeps copying row 46 and not the last
one! Any thoughts??

Sheets("Sheet1").Select
* * Range("A1").Select
* * Selection.End(xlDown).Select
* * Range("B46:M46").Select
* * Selection.Copy

--
James.


call me old fashioned but i would go about doing it this way:

do while workbooks(Yr_Book).worksheets(Yr_Sheet).cells(i,1) <""
i=i+1
loop

last_row=i-1 'this may be i and not i-1, proof it when you test the
algo.

i=1

do while workbooks(Yr_Book).worksheets(Yr_Sheet).cells(last )row,i)<""
i=i+1
loop

last_col=i 'again, may be i-1 i forget what happens.

workbooks(Yr_Book).worksheets(Yr_Sheet).range(cell s(last_row,1),cells
(last_row,last_col)).select
selection.copy

'or
dim Holder(0 to 0, 1 to last_col)

for i=1 to last_col
holder(0,i)=workbooks(Yr_Book).worksheets(Yr_Sheet ).cells(last_row,i)
end

'go to new workbook and output array.
'this is not the most computationally simple way, but the most
computationally precise.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Row find Macro

Non-macro code. The macro code suffers if there are empty cells,
while the code below might find an empty row; you'd need to add a test
for empty rows and work back up until it finds a value:


Dim lngRows as long
Dim wksTemp as Workheet

set wksTemp = ThisWorkbook.Sheets("Sheet1")
lngRows = wksTemp.UsedRange.Rows.Count

wksTemp.Range(Cells(lngRows,2),Cells(lngRows,13)). Copy



On Nov 13, 12:30*pm, James wrote:
Hi

I'm trying to write some code so as that I can copy the last row in a sheet.
Each day a new row is added so I need it to find the new row each day. I have
written the below however although it keeps copying row 46 and not the last
one! Any thoughts??

Sheets("Sheet1").Select
* * Range("A1").Select
* * Selection.End(xlDown).Select
* * Range("B46:M46").Select
* * Selection.Copy

--
James.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Row find Macro

Are you the OP (hard to tell because the email addresses are different)?
I'll assume you are...

The macro code can be made to do what you want... you just have to tell what
that is. Your first post didn't give us much to go on and this second post
of yours doesn't really tell us too much more. Can you describe in words
what you have and what you want from it?

As an aside, if you are looking for the last row with any data (not formula
displaying empty string) in it, no matter what the column, then you can use
this...

LastUsedRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row

--
Rick (MVP - Excel)


"james" wrote in message
...
Non-macro code. The macro code suffers if there are empty cells,
while the code below might find an empty row; you'd need to add a test
for empty rows and work back up until it finds a value:


Dim lngRows as long
Dim wksTemp as Workheet

set wksTemp = ThisWorkbook.Sheets("Sheet1")
lngRows = wksTemp.UsedRange.Rows.Count

wksTemp.Range(Cells(lngRows,2),Cells(lngRows,13)). Copy



On Nov 13, 12:30 pm, James wrote:
Hi

I'm trying to write some code so as that I can copy the last row in a
sheet.
Each day a new row is added so I need it to find the new row each day. I
have
written the below however although it keeps copying row 46 and not the
last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy

--
James.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Row find Macro

Hi Rick and everyone else

Have been away all weekend (so no different James!) but thank you for your
responses and will take a look first thing this morning!


--
James.


"Rick Rothstein" wrote:

Are you the OP (hard to tell because the email addresses are different)?
I'll assume you are...

The macro code can be made to do what you want... you just have to tell what
that is. Your first post didn't give us much to go on and this second post
of yours doesn't really tell us too much more. Can you describe in words
what you have and what you want from it?

As an aside, if you are looking for the last row with any data (not formula
displaying empty string) in it, no matter what the column, then you can use
this...

LastUsedRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row

--
Rick (MVP - Excel)


"james" wrote in message
...
Non-macro code. The macro code suffers if there are empty cells,
while the code below might find an empty row; you'd need to add a test
for empty rows and work back up until it finds a value:


Dim lngRows as long
Dim wksTemp as Workheet

set wksTemp = ThisWorkbook.Sheets("Sheet1")
lngRows = wksTemp.UsedRange.Rows.Count

wksTemp.Range(Cells(lngRows,2),Cells(lngRows,13)). Copy



On Nov 13, 12:30 pm, James wrote:
Hi

I'm trying to write some code so as that I can copy the last row in a
sheet.
Each day a new row is added so I need it to find the new row each day. I
have
written the below however although it keeps copying row 46 and not the
last
one! Any thoughts??

Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select
Range("B46:M46").Select
Selection.Copy

--
James.


.



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 that does a find and then find next Galway[_2_] Excel Programming 1 January 1st 09 08:10 PM
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
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
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 12:29 AM.

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"