| View previous topic :: View next topic |
| Author |
Message |
Chris. Guest
|
Posted: Fri Aug 29, 2008 8:14 pm Post subject: Excel Macro for Copy and Paste Looping |
|
|
I need help with a macro to extract data from certain cells from a database (an Excel spreadsheet named MASTER) to another spreadsheet (an Excel spreadsheet named BETA)
In the MASTER spreadsheet is a list of ID numbers going down, and going across is the data for that ID.
What I am looking for is a macro that will allow me to input and ID number into the spreadsheet BETA, and when I do that, it will take all the corresponding information from the MASTER and put it into cells in BETA. But only copy over specific cells, and not the entire row.
Thanks in advance.
MASTER
ID NAME LOCATION STATE SIZE NATIONALITY YEAR SERIALS DAY OF WEEK
111111 AAAA1 M1 CALIFORNIA 123 1111 2002 12345 MONDAY
111111 AAAA2 M3 NEW YORK 123 2222 2003 54321 FRIDAY
111111 AAAA3 M5 ARIZONA 321 3333 2001 48576 SUNDAY
111111 AAAA4 M7 OHIO 321 4444 2003 17364 SUNDAY
111111 AAAA5 M8 CALIFORNIA 345 5555 2002 67439 TUESDAY
111111 AAAA6 BA ARIZONA 345 6666 2003 59240 TUESDAY
121212 BBBB1 CV OHIO 543 7777 2001 44924 FRIDAY
121212 BBBB2 CB CALIFORNIA 465 8888 2002 87654 FRIDAY
121212 BBBB3 DJ OHIO 332 9999 2003 83456 FRIDAY
121212 BBBB4 SL ARIZONA 444 AAAA 2003 67494 FRIDAY
121212 BBBB5 DB CALIFORNIA 456 SSSS 2001 76553 FRIDAY
131313 CCCC1 SM NEW YORK 342 DDDD 2001 44009 TUESDAY
131313 CCCC2 KK ARIZONA 675 FFFF 2003 44986 TUESDAY
131313 CCCC3 DS NEW YORK 365 CCCC 2003 66098 TUESDAY
131313 CCCC4 MN ARIZONA 654 GGGG 2002 66044 TUESDAY
131313 CCCC5 KL OHIO 768 YYYY 2003 55402 SUNDAY
131313 CCCC6 DD ARIZONA 276 RRRR 2003 55087 SUNDAY
131313 CCCC7 HJ NEW YORK 236 UUUU 2001 55321 SUNDAY
131313 CCCC8 BA ARIZONA 673 KKKK 2003 34567 SUNDAY
131313 CCCC9 CB NEW YORK 768 JJJJ 2001 65098 SUNDAY
BETA (from ID 121212)
BBBB1 CV OHIO 543 7777
BBBB2 CB CALIFORNIA 465 8888
BBBB3 DJ OHIO 332 9999
BBBB4 SL ARIZONA 444 AAAA
BBBB5 DB CALIFORNIA 456 SSSS |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
|
| Back to top |
|
 |
Hasso
Joined: 23 Mar 2005 Posts: 158 Location: Germany
|
Posted: Mon Sep 01, 2008 11:10 am Post subject: |
|
|
Chris,
this could be easily done with a small VBA script in Excel itself (without AHK): | Code: | Sub values()
i = 2
j = 2
id = Worksheets("BETA").Cells(1, 1) 'Put your ID in cell A1
While Worksheets("MASTER").Cells(i, 1) <> ""
If Worksheets("MASTER").Cells(i, 1) = id Then
For k = 1 To 6
Worksheets("BETA").Cells(j, k ) = Worksheets("MASTER").Cells(i, k )
Next
j = j + 1
End If
i = i + 1
Wend
End Sub
|
_________________ Hasso
Programmers don't die, they GOSUB without RETURN |
|
| Back to top |
|
 |
|