A Macro that imports row data from another sheet?

redapplesonly

New Member
Joined
Jun 28, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone, I need a Macro that populates a range of cells with a formula. At first, I thought this would be an easy problem... but I'm starting to think that it is a more advanced problem than I originally guessed.

To explain: In my spreadsheet, I have two sheets: PERM_DATA and PLAY_WITH_DATA. PERM_DATA is populated with product data, and is never meant to be altered by the user. Let's say it looks like this:

PRODUCTCost_to_ProduceWholesale_PriceRetail_Price
TeeShirt_A$5$8$10
TeeShirt_B$6$8$14
TeeShirt_C$3$6$9

The data on this sheet is static; the user is never supposed to modify it. But let's say on the other sheet, PLAY_WITH_DATA, I want to give the user an identical set of data with which to play around. On the first visit, PLAY_WITH_DATA would look like this:

PRODUCTCost_to_ProduceWholesale_PriceRetail_Price
<<Drop-down Menu>>
<<Drop-down Menu>>
<<Drop-down Menu>>

Where the drop-down menus in Column A list all the PRODUCTS from PERM DATA. The idea is, if the user wants to play with the numbers associated with TeeShirt_A, they can select "TeeShirt_A" from any drop-down menu, and then the rest of the TeeShirt_A numbers will populate into the rest of the row. This formula should do that:

VBA Code:
=IFERROR(VLOOKUP($B1,'PERM_DATA'!$A$2:$I$11,2,0),"")

The user can then "play with" (i.e. change) the data on the PLAY_WITH_DATA tab. The original data is preserved on PERM_DATA, and can be re-imported into PLAY_WITH_DATA, should we run the Macro again.

So I'm wracking my brain on how to do this. I guess, first I need a Macro that populates the above formula into every cell in the target row, maybe something like this:

Code:
Sub ImportRowFromPermData()

Dim i As Integer
For i = 2 To 4
  Cells(2, i).Formula = IFERROR(VLOOKUP($B2,'PERM_DATA'!$A$2:$I$11,i,0),"")
Next i

End Sub

The above kicks up a syntax error within the formula, however; Excel doesn't like the reference to "$B2" I don't know why.

I would still need to figure out how to tie the above in with a PLAY_WITH_DATA row's drop-down menu.

So I realize that I'm prob attempting something harder than I can handle, but I thought I'd ask: Is my approach way off? Does anyone see my error? Or is there any easier approach? Any advice is welcomed. Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try
Excel Formula:
Cells(2, i).Formula = "=IFERROR(VLOOKUP($B2,'PERM_DATA'!$A$2:$I$11," & i & ",0),"")"
(didn't check).
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top