Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default some final help


Hi

this almost works - my only problem is that i don't know how to selec
the very last row and paste the data - any ideas?


Sub CopyPaste()

Range("h5").Activate
Set ac = ActiveCell
ac.Copy


Do
Windows("source.xls").Activate
Sheets("Data").Activate
Range("a1").Activate
Range("a2").Columns("A:A").EntireColumn.Select
Selection.Find(what:=ac).Select
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
Windows("Database.xls").Activate
Sheets("Data").Select


' the next lines need to be dynamic - to find the last row in column a
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Offset(7562, 0).Range("A1").Select


'this won't paste because the areas are different - not sure how to fi
this
ActiveCell.EntireRow.Paste

Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(-1, 0) = ""

End Sub

thank

--
rbekka3
-----------------------------------------------------------------------
rbekka33's Profile: http://www.excelforum.com/member.php...fo&userid=1403
View this thread: http://www.excelforum.com/showthread.php?threadid=26274

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default some final help

Hi rbekkR,

You can return the last populated cell in column A with an expression like:

Set LastCell = ActiveSheet.Cells(Rows.Count, "A").End(xlUp)

Similarly, the following empty cell would be returned by:

Set NextCell = ActiveSheet.Cells(Rows.Count, "A").End(xlUp)(2).

It is rarely necessary to select, so removing selections/activations and
dropping your Do ...Loop, your code could, perhaps, be simplified to
something like:

Sub CopyPaste2()
Dim RngSrc As Range
Dim RngDest As Range
Dim ac As Variant

ac = ActiveSheet.Range("H5").Value

Set RngSrc = Workbooks("source.xls").Sheets("Data"). _
Columns(1).Find(What:=ac)

If Not RngSrc Is Nothing Then
With Workbooks("Database.xls").Sheets("Data")
Set RngDest = .Cells(Rows.Count, "A").End(xlUp)(2)
End With

RngSrc.EntireRow.Copy RngDest
Else
'The search data not found!
End If
End Sub


Check this on a COPY of your workbook until you are happy that it correctly
reflects your intentions.

---
Regards,
Norman



"rbekka33" wrote in message
...

Hi

this almost works - my only problem is that i don't know how to select
the very last row and paste the data - any ideas?


Sub CopyPaste()

Range("h5").Activate
Set ac = ActiveCell
ac.Copy


Do
Windows("source.xls").Activate
Sheets("Data").Activate
Range("a1").Activate
Range("a2").Columns("A:A").EntireColumn.Select
Selection.Find(what:=ac).Select
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
Windows("Database.xls").Activate
Sheets("Data").Select


' the next lines need to be dynamic - to find the last row in column a
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Offset(7562, 0).Range("A1").Select


'this won't paste because the areas are different - not sure how to fix
this
ActiveCell.EntireRow.Paste

Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Offset(-1, 0) = ""

End Sub

thanks


--
rbekka33
------------------------------------------------------------------------
rbekka33's Profile:
http://www.excelforum.com/member.php...o&userid=14033
View this thread: http://www.excelforum.com/showthread...hreadid=262740



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
final return! via135 Excel Worksheet Functions 5 January 11th 08 11:00 AM
Final day of month B Excel Worksheet Functions 3 July 25th 07 12:49 AM
My Final #DIV/0! that I'd like to say Goodbye to! Dan the Man[_2_] Excel Worksheet Functions 20 July 23rd 07 05:40 PM
Help Finding the Final Row No Name Excel Programming 7 May 21st 04 03:13 AM
Need final code tweak Phil Hageman Excel Programming 12 August 16th 03 08:53 PM


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

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

About Us

"It's about Microsoft Excel"