ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro referencing multiple worksheets (https://www.excelbanter.com/excel-discussion-misc-queries/113467-macro-referencing-multiple-worksheets.html)

JULZ

Macro referencing multiple worksheets
 
Hi. I'm new to Excel macros, but not Excel. Trying to write a macro to do
the following, but I'm not sure how.

Worksheet 1, Columns A & B contain first and last names. Column C is
currently blank.
Worksheet 2, Columns A & B contain first and last names. Column C contains
cost.

Worksheet 2 contains only some of the names in Worksheet 1.

Want a macro to compare first and last names of the two worksheets. When
they match, take the cost in Worksheet 2 and place it in Column C of
Worksheet 1. When they don't match, move onto the next name in Worksheet 1
until end of data.

Here's the next kicker:

Some of the rows in Worksheet 2 contain information on the same name. For
example, Jane Doe may have 2 rows of information for cost, which would need
to be added together and put in Column C on worksheet 1.

For example,

Worksheet 1:
Jane Doe
Joe Smith
Ted Blake
Hank Walters

Worksheet 2:
Joe Smith $35.00
Jane Doe $15.00
Hank Walters $5.00
Jane Doe $10.00



Worksheet 1 Result after Macro Runs:
Jane Doe $25.00
Joe Smith $35.00
Ted Blake
Hank Walters $5.00



I think I would use a do...while loop, but don't understand how to reference
multiple worksheets or even attempt the kicker part.

Any help would be greatly appreciated!

Thanks in advance,

Julz

Gary L Brown

Macro referencing multiple worksheets
 
Use the SumIf( ) function in worksheet 1 column C
HTH,
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


"Julz" wrote:

Hi. I'm new to Excel macros, but not Excel. Trying to write a macro to do
the following, but I'm not sure how.

Worksheet 1, Columns A & B contain first and last names. Column C is
currently blank.
Worksheet 2, Columns A & B contain first and last names. Column C contains
cost.

Worksheet 2 contains only some of the names in Worksheet 1.

Want a macro to compare first and last names of the two worksheets. When
they match, take the cost in Worksheet 2 and place it in Column C of
Worksheet 1. When they don't match, move onto the next name in Worksheet 1
until end of data.

Here's the next kicker:

Some of the rows in Worksheet 2 contain information on the same name. For
example, Jane Doe may have 2 rows of information for cost, which would need
to be added together and put in Column C on worksheet 1.

For example,

Worksheet 1:
Jane Doe
Joe Smith
Ted Blake
Hank Walters

Worksheet 2:
Joe Smith $35.00
Jane Doe $15.00
Hank Walters $5.00
Jane Doe $10.00



Worksheet 1 Result after Macro Runs:
Jane Doe $25.00
Joe Smith $35.00
Ted Blake
Hank Walters $5.00



I think I would use a do...while loop, but don't understand how to reference
multiple worksheets or even attempt the kicker part.

Any help would be greatly appreciated!

Thanks in advance,

Julz



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

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