Calculate values with

Pastafarian

New Member
Joined
Feb 21, 2012
Messages
30
Hi,

I have 2 sheets. Sheet 1 contains rows with orders. Each order has multiple products. Sheet 2 has the prices of those products, with in each column a different country (thus different price) and each row an other product.

For each order I'm trying to calculate the price for of all products combined, so I tried out to get the price of 1 product, but I'm doing something wrong.

This is the code that I'm using right now:
Code:
With Sheets("Sheet1")

    For i = 2 To AmountofOrders
    
    'On Error Resume Next
    
    .Cells(i, 25) = .Cells(i, 30) * WorksheetFunction.HLookup([B][SIZE="3"]Cells(i, 4)[/SIZE][/B], Worksheets("Sheet2").Range("AF2:AS50"), 2, False)
    
    
    Next i

End With

It basicly multiplies the amount of a product with the price (=value that needs to be looked up) and repeats that proces for all orders.


I read somewhere the highlighted part maybe won't work, but I can't figure out how to do it.
What is the best way to do this?


Thanks! :pray:


From Holland with love,
Pastafarian
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Pastafarian,

Your code as it's written works fine for me. It sounds like you may not want to use HLookup. By using HLookup your code is seeking a match for your search criteria in row 2. You mentioned your prices go across the columns by country and you have each different product in a new row on sheet 2. If you're looking for a match based on a product number/name from sheet1 and the products are listed in rows on sheet2 then you wouldn't want to use HLookup which will search across the columns. You could consider using VLookup.

Steve
 
Upvote 0
I already found it out. Its rather ashaming, but I forgot the dot in .Cells in the highlighted area. :oops: Thanks anyway!
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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