Excel Macro Help - Trying to create either a function or macro

I am at my wits end trying to create either a function or a macro to import data from one worksheet to another. I have total sales for a SKU on one worksheet and on another worksheet, I have the same SKU's but in a different order and cannot readjust the order. In the second worksheet I want it to pull total sales for that SKU from the first worksheet and enter it into the cell on the second worksheet that corresponds to that SKU.

For example:

Worksheet 1:

SKU YTD Sales xxxxxx1 4 xxxxxx2 6 xxxxxx3 8 xxxxxx4 9

Worksheet 2: SKU YTD Sales xxxxxx1 this is where I want the data put into from Worksheet 1 xxxxxx4 xxxxxx2 xxxxxx3

I am trying to eliminate would could end up to be days upon days of data entry. Any ideas?

THANKS!

7 Comments
 

use a sumif on worksheet 2: Assuming that SKU and YTD Sales are A1 and B1: in ws2 in B2, put =SUMIF('Sheet1'!$A$2:$B$5000,$A2,'Sheet1'!$B$2:$B$5000)

have fun edit: above poster is right as well, the only reason i used sumif is to account for the possibility of the sku being listed multiple times on worksheet 1

 

thanks! I had tried VLOOKUP numerous times without success but your guys' reassuring comments kept me at it and I finally got it to work.

 
Best Response

The best way to do this via excel macros is to create a loop with this kind of structure:

If Workbooks(1).Sheets(1).Cells(rowNum, 1) = "SKU1" Then Workbooks(2).Sheets(1).Cells(1, colNum) = Workbooks(1).Sheets(1).Cells(rowNum, 5) End If

rowNum is a variable that changes every time the loop is finished via rowNum = rowNum + 1 at the bottom of the loop.

The way you want to read this is "If the entry in the first column and rowNum row of my first worksheet equals SKU1, then my second worksheet pulls the value 5 columns over from that entry and plugs it into the first column of the first row."

The idea here is that the loop checks every single row for "SKU1" and when it finds SKU1 it takes the information you want. So what you need to do is make a loop that has a statement like the one above for each individual SKU# so that the loop checks every line for every SKU#. colNum may or may not be something you need depending on whether or not you plan on having multiple dates going.

I know this can be confusing but send me a PM if you have anymore questions. This way is better than VLOOKUP once you put in the initial grunt work of understanding what's going on.

 

The reason I would use VBA over vlookup is once you have a loop set up, you could keep updating the sheet and the macro would still work. If you simply use the vlookups, you would have to put a ton more vlookups in.

 

Rerum perferendis unde amet sapiente ut explicabo. Unde aut quo animi deleniti perferendis. Dolore nihil expedita voluptas. Non ea tempore recusandae mollitia doloremque iure consequatur id.

Aliquam illum ut accusamus velit. Minus tempore quisquam explicabo enim fugit et. Molestiae eveniet consequatur est consequatur distinctio aliquam.

Magnam ut qui ut placeat qui distinctio totam. Vel quae nihil nemo. Consequatur omnis temporibus harum quia at. Dolores voluptas animi incidunt quas. Eum nihil ut a.

Amet consequatur dolore vero quis nemo omnis est. Est aliquam exercitationem ducimus accusamus. Sit ut alias assumenda ut ullam nostrum eius. Sit molestiae quia impedit libero. Saepe est sequi est nisi alias id et. Quia nobis ab et impedit et quam.

Career Advancement Opportunities

July 2026 Investment Banking

  • Evercore 01 99.4%
  • Moelis & Company 01 98.9%
  • JPMorgan 01 98.3%
  • Guggenheim Partners 01 97.7%
  • Morgan Stanley 07 97.2%

Overall Employee Satisfaction

July 2026 Investment Banking

  • Moelis & Company No 99.4%
  • Evercore No 98.9%
  • Morgan Stanley 01 98.3%
  • Banco Santander 02 97.7%
  • BMO Capital Markets 12 97.2%

Professional Growth Opportunities

July 2026 Investment Banking

  • Evercore 01 99.4%
  • Moelis & Company 01 98.9%
  • Morgan Stanley 06 98.3%
  • Goldman Sachs 01 97.7%
  • JPMorgan 01 97.2%

Total Avg Compensation

July 2026 Investment Banking

  • Vice President (16) $429
  • Associates (46) $258
  • 3rd+ Year Analyst (8) $210
  • 2nd Year Analyst (22) $179
  • Intern/Summer Associate (14) $159
  • 1st Year Analyst (80) $150
  • Intern/Summer Analyst (73) $101
notes
16 IB Interviews Notes

“... there’s no excuse to not take advantage of the resources out there available to you. Best value for your $ are the...”

Leaderboard

1
redever's picture
redever
99.2
2
kanon's picture
kanon
99.0
3
BankonBanking's picture
BankonBanking
99.0
4
Secyh62's picture
Secyh62
99.0
5
dosk17's picture
dosk17
98.9
6
GameTheory's picture
GameTheory
98.9
7
Betsy Massar's picture
Betsy Massar
98.9
8
CompBanker's picture
CompBanker
98.9
9
DrApeman's picture
DrApeman
98.9
10
numi's picture
numi
98.8
success
From 10 rejections to 1 dream investment banking internship

“... I believe it was the single biggest reason why I ended up with an offer...”