Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Autocopy row from several worksheet to another workbook

I assumed that you're pasting into the same worksheet.

Option Explicit
Sub testme()

Dim Wkbk As Workbook
Dim wks As Worksheet
Dim destWks As Worksheet
Dim destCell As Range

Dim myRng As Range
Dim FoundCell As Range
Dim AllCells As Range
Dim FirstAddress As String
Dim whatToFind As String

Set Wkbk = Workbooks("book1.xls")
Set destWks = Workbooks("book2.xls").Worksheets("sheet1")

whatToFind = "hithere!"

For Each wks In Wkbk.Worksheets
With wks
FirstAddress = ""
Set myRng = .Range("B:b")
With myRng
Set FoundCell = .Cells.Find(what:=whatToFind, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False)

If FoundCell Is Nothing Then
'do nothing
Else
FirstAddress = FoundCell.Address
Do
With destWks
Set destCell = .Cells(.Rows.Count, "B").End(xlUp) _
.Offset(1, -1)
End With
FoundCell.EntireRow.Resize(1, 14).Copy _
Destination:=destCell
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address < FirstAddress
End If
End With
End With
Next wks

End Sub

Both workbooks must be open.

Set Wkbk = Workbooks("book1.xls")
Set destWks = Workbooks("book2.xls").Worksheets("sheet1")

book1.xls is the workbook that will be searched through.
sheet1 in book2.xls will be where the data will be pasted.

I used column b to find the next available row.

Take a look at that .find line. You'll want to adjust it to match what you need
(xlwhole/xlpart, matchcase stuff).


hme wrote:

Hi
How can copy a row with a given range (text) in column B, from several
worksheets to another workbook.
thanks
HME

--
hme
------------------------------------------------------------------------
hme's Profile: http://www.excelforum.com/member.php...o&userid=15930
View this thread: http://www.excelforum.com/showthread...hreadid=276146


--

Dave Peterson

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
How can I autocopy text from one textbox to another using VBA in E SunFUd01 Excel Discussion (Misc queries) 0 November 18th 09 06:24 PM
Autocopy formula in tables Stacey Excel Discussion (Misc queries) 1 December 20th 07 10:06 AM
Autocopy formula without VB johnsonlnl29 Excel Discussion (Misc queries) 1 December 15th 06 04:28 PM
Autocopy formula to cells ASU Excel Discussion (Misc queries) 1 September 8th 06 04:43 PM
Autocopy formula to cells Marie Bayes Excel Discussion (Misc queries) 4 August 1st 06 04:32 PM


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