Created
May 3, 2024 15:05
-
-
Save drahosistvan/53fb2302b250a20adca561d1b8e5dd71 to your computer and use it in GitHub Desktop.
VBA beadando - Milton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub CalcSales() | |
'Define main search, currency search and product search variables | |
Dim currentCell As Range | |
Dim productCell As Range | |
Dim currencyCell As Range | |
' Loop from I7 until empty cell is found, and calculate expected output | |
Set currentCell = Range("I7") | |
Do While Not IsEmpty(currentCell.Value) | |
'Find product data | |
Set productCell = Range("B7") | |
Do While Not IsEmpty(productCell.Value) | |
If currentCell.Value = productCell.Value Then | |
Exit Do | |
End If | |
Set productCell = productCell.Offset(1, 0) | |
Loop | |
'Find currency data | |
Set currencyCell = Range("B22") | |
Do While Not IsEmpty(currencyCell.Value) | |
If currencyCell.Value = productCell.Offset(0, 2).Value Then | |
Exit Do | |
End If | |
Set currencyCell = currencyCell.Offset(1, 0) | |
Loop | |
currentCell.Offset(0, 2).Value = productCell.Offset(0, 1).Value | |
currentCell.Offset(0, 3).Value = priceInHuf(productCell.Offset(0, 3).Value, currencyCell.Offset(0, 2).Value, currencyCell.Offset(0, 1).Value) * currentCell.Offset(0, 1).Value | |
currentCell.Offset(0, 4).Value = productCell.Offset(0, 4).Value * currentCell.Offset(0, 1).Value | |
currentCell.Offset(0, 5).Value = calculateComment(productCell.Offset(0, 4).Value * currentCell.Offset(0, 1).Value) | |
Set currentCell = currentCell.Offset(1, 0) | |
Loop | |
End Sub | |
'Function, to calculate unit price for product in HUF | |
Function priceInHuf(foreignPrice, currencyRate, currencyQty) | |
priceInHuf = foreignPrice * currencyRate / currencyQty | |
End Function | |
'Function to calculate comment based on weight | |
Function calculateComment(weight) | |
If weight > 15 Then | |
calculateComment = "Nagy csomag" | |
Else | |
calculateComment = "Kis csomag" | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment