Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to Search and Copy

Hello there, I am looking to create a macro that does the following;

1. Copy data in a cell from a workbook
2. Paste into Find in the personal.xls
3. Find the data that matches
4. Copy and paste a range from the personal.xls
5. Paste into the first workbook
6. Repeat for a range of cells

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Macro to Search and Copy

David,

For example, this will find the values from cells A2:A11 of the active sheet, find those values on
sheet1 of persaonal.xls, and copy the 5 cells immediately to the right of the found cells, and paste
the values into the cells starting in column B of the active sheet.

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Cells.Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

Or, be more specific about where to search:

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Range("A:A").Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

You could also use VLOOKUP formulas to do the same.

HTH,
Bernie
MS Excel MVP


"davidnagel" wrote in message
...
Hello there, I am looking to create a macro that does the following;

1. Copy data in a cell from a workbook
2. Paste into Find in the personal.xls
3. Find the data that matches
4. Copy and paste a range from the personal.xls
5. Paste into the first workbook
6. Repeat for a range of cells

Any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to Search and Copy

Bernie, thank you for your reply, bear in mind, I intend this macro to run
from the personal.xls on the open workbook, would some code need to adjusted
to accomadate this?

"Bernie Deitrick" wrote:

David,

For example, this will find the values from cells A2:A11 of the active sheet, find those values on
sheet1 of persaonal.xls, and copy the 5 cells immediately to the right of the found cells, and paste
the values into the cells starting in column B of the active sheet.

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Cells.Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

Or, be more specific about where to search:

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Range("A:A").Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

You could also use VLOOKUP formulas to do the same.

HTH,
Bernie
MS Excel MVP


"davidnagel" wrote in message
...
Hello there, I am looking to create a macro that does the following;

1. Copy data in a cell from a workbook
2. Paste into Find in the personal.xls
3. Find the data that matches
4. Copy and paste a range from the personal.xls
5. Paste into the first workbook
6. Repeat for a range of cells

Any ideas?




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Macro to Search and Copy

David,

I wrote it to work from any workbook, to act upon the currently active sheet, as long as
Personal.xls is open. Also, I did not include any error checking, in the case that the value in
cells A2:A11 is not found - would the value ever not be found?

If you want to run it from Personal.xls, you could change

Workbooks("Personal.xls").

to

ThisWorkbook.

And also, for a little more flexibility, change

For Each myC In Range("A2:A11")

to

For Each myC In Selection

Then select the cells that you want to lookup prior to running the macro.

HTH,
Bernie
MS Excel MVP


"davidnagel" wrote in message
...
Bernie, thank you for your reply, bear in mind, I intend this macro to run
from the personal.xls on the open workbook, would some code need to adjusted
to accomadate this?

"Bernie Deitrick" wrote:

David,

For example, this will find the values from cells A2:A11 of the active sheet, find those values
on
sheet1 of persaonal.xls, and copy the 5 cells immediately to the right of the found cells, and
paste
the values into the cells starting in column B of the active sheet.

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Cells.Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

Or, be more specific about where to search:

Dim myC As Range

Dim myC As Range
For Each myC In Range("A2:A11")
Workbooks("Personal.xls").Worksheets("Sheet1"). _
Range("A:A").Find(myC.Value).Offset(0, 1).Resize(1, 5).Copy myC(1, 2)
Next myC

You could also use VLOOKUP formulas to do the same.

HTH,
Bernie
MS Excel MVP


"davidnagel" wrote in message
...
Hello there, I am looking to create a macro that does the following;

1. Copy data in a cell from a workbook
2. Paste into Find in the personal.xls
3. Find the data that matches
4. Copy and paste a range from the personal.xls
5. Paste into the first workbook
6. Repeat for a range of cells

Any ideas?






  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to Search and Copy

Thank you for your assistance Bernie, your advice worked a treat and the
Macro produces a perfect worksheet. Can we not share karma points here? ;-)

Kind Regards and Best Wishes,

David.
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 to search column, copy row, and copy to another sheet in same Rockhound Excel Discussion (Misc queries) 1 December 9th 06 04:16 PM
Search and Copy CribbsStyle Excel Worksheet Functions 0 October 6th 06 08:02 PM
Search and copy certain text Rusty Excel Discussion (Misc queries) 2 July 20th 06 12:11 AM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Search and copy Hru48 Excel Discussion (Misc queries) 1 October 31st 05 03:56 PM


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