ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I create a macro with a variable search feature? (https://www.excelbanter.com/excel-discussion-misc-queries/146437-how-do-i-create-macro-variable-search-feature.html)

punkyfire

How do I create a macro with a variable search feature?
 
I have 3 excel documents.
1 has single column with 20 rows containing unique numbers.
2nd has 8 columns with 936 rows
3rd is blank

I want to write a macro that will copy an individual number in the first
document, search for it in the 2nd document, copy the entire row holding that
number from the 2nd and paste it into the 3rd blank document and cursor down
one row. I then want it to go back to the 1st document cursor down one row
and end.

When I try to write the macro, it records the first number from the first
document within the macro, so it won't automatically search for the document
within the row I am in.

Any help would be appreciated.
--
--
Mary

Toppers

How do I create a macro with a variable search feature?
 
Please post your code.

"punkyfire" wrote:

I have 3 excel documents.
1 has single column with 20 rows containing unique numbers.
2nd has 8 columns with 936 rows
3rd is blank

I want to write a macro that will copy an individual number in the first
document, search for it in the 2nd document, copy the entire row holding that
number from the 2nd and paste it into the 3rd blank document and cursor down
one row. I then want it to go back to the 1st document cursor down one row
and end.

When I try to write the macro, it records the first number from the first
document within the macro, so it won't automatically search for the document
within the row I am in.

Any help would be appreciated.
--
--
Mary


punkyfire

How do I create a macro with a variable search feature?
 
Sub Cull()
'
' Cull Macro
' Macro recorded 6/14/2007 by
'
' Keyboard Shortcut: Ctrl+k
'
Selection.Copy
Windows("C02_ORIG_LOST_52307.xls").Activate
Cells.Find(What:="5010045", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -6).Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Culled_ICNs.xls").Activate
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
Windows("C02_Extracts.xls").Activate
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub

--
Mary


"Toppers" wrote:

Please post your code.

"punkyfire" wrote:

I have 3 excel documents.
1 has single column with 20 rows containing unique numbers.
2nd has 8 columns with 936 rows
3rd is blank

I want to write a macro that will copy an individual number in the first
document, search for it in the 2nd document, copy the entire row holding that
number from the 2nd and paste it into the 3rd blank document and cursor down
one row. I then want it to go back to the 1st document cursor down one row
and end.

When I try to write the macro, it records the first number from the first
document within the macro, so it won't automatically search for the document
within the row I am in.

Any help would be appreciated.
--
--
Mary



All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com