• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Need a help with vba script|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Need a help with vba script|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosNeed a help with vba script
sp_PrintTopic sp_TopicIcon
Need a help with vba script
Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
1
February 13, 2019 - 1:05 am
sp_Permalink sp_Print

Hello there. I'm trying to write a macro(vba) script which shows the lowest price for each SKU(ItemNumber) I enter. I have 5 columns: SKU(ItemNumber), Itemtitle, Supplier1Price, Supplier2Price, Supplier3Price. Suppliers have their own prices. The main struggle is that I don't know how to write the code to show me multiple results I enter.

 

This is the code:

Option Explicit

Sub LowPrice()
Dim lr As Long, i As Long, j As Integer
Dim ans As Double, sku As String, col As Variant
Dim number As Integer, numeris As String
j = 1
Application.ScreenUpdating = False
lr = Range("A" & Rows.Count).End(xlUp).Row
number = InputBox("How many SKUS you gonna enter?")
While j <= number
sku = InputBox("What SKU to search?")
j = j + 1

Wend
For i = 2 To lr

If Range("A" & i) = sku Then
sku = WorksheetFunction.Min(Range("C" & i & ":G" & i))

End If

Next i
MsgBox ("Minimum Price is " & sku)
Application.ScreenUpdating = True

End Sub

Attached a file to make it more understandable.

Hope someone can help me. Thank you.

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
February 13, 2019 - 12:23 pm
sp_Permalink sp_Print

Hi sigitas

Give this a try.

I have added 2 helper columns F and G to make the coding a bit easier.

Good luck

Sunny

Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
3
February 13, 2019 - 5:13 pm
sp_Permalink sp_Print

Hello there, thank you for your help, but it doesn't work the way it should work. If I try to change the SKU to the real one - the search box shows that there is no such SKU. 

Added a picture to show how it looks like. 

No Such SKUImage Enlarger

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
4
February 13, 2019 - 6:09 pm
sp_Permalink sp_Print

It is not working because the SKU you attached with your file is text but the actual is a number.

The codes is based on what you supplied earlier.

Please try the new attachment.

If it is still not working then please attach the actual SKU in a file for us to take a look.

Sunny

Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
5
February 14, 2019 - 5:08 pm
sp_Permalink sp_Print

Hello. Sorry that I'm wasting your valuable time, I appreciate your help. It works very well, but the problem is that I want to add more SKU's at once, like 10 to make the work more effective. I tried to do this on my own but unfortunately failed. 

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
6
February 14, 2019 - 8:42 pm
sp_Permalink sp_Print

Other than the 10 SKU that you need to see at once, is the file that I gave you working properly? 

Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
7
February 14, 2019 - 11:40 pm
sp_Permalink sp_Print

Yes, it works perfectly

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
8
February 15, 2019 - 1:42 am
sp_Permalink sp_Print

Furthermore I am wondering why you want a user form to do the searches.

You could have easily done it using Data Validation (DV) and VLOOKUP in another sheet.

Advantage of such a approach:

1) Easy to implement/troubleshoot

2) Can add as many DV/VLOOKUP as you want

3) Can print out the results.

4) Require almost no VBA/macro (unless you want to clear the DV with VBA instead of manually).

Sunny

Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
9
February 15, 2019 - 2:27 am
sp_Permalink sp_Print

Do you know the way I can do it? I started to do it with formulas, but failed. From the very start I wanted to do it the easiest way possible. 

I will attach a picture and explain how I really want it to look like. 

Image Enlarger

In the right you can see the table with headers: SKU Example, Qty, Price, Supplier

On the left you can see a database with all the info. 

We get many invoices from the customers with the SKU's and quantities they want. 

My aim is just simply copy/paste SKU's to the column from the invoice and the formula should look for the lowest price for the certain SKU and show the supplier.

SKU and qty are added manually.

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
10
February 15, 2019 - 10:41 am
sp_Permalink sp_Print sp_EditHistory

OK now I understand why you wanted so many SKU. In this case using a userform is not recommended.

Please refer attached.

You only need to enter/paste the SKU numbers you need into column A of the ENQUIRY sheet.

It uses an Excel Table so the formula auto-populate when you enter any data into column A.

If you need to know more about Tables then refer here https://www.myonlinetraininghu.....cel-tables

Good luck.

Sunny

Avatar
sigitas lev
Member
Members
Level 0
Forum Posts: 6
Member Since:
February 13, 2019
sp_UserOfflineSmall Offline
11
February 15, 2019 - 6:07 pm
sp_Permalink sp_Print

Thank you very much for your help! I really appreciate it. Have a good day!

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
12
February 16, 2019 - 11:07 am
sp_Permalink sp_Print

No problem.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: RAQUEL ACION, Dana Friedt, Shawn Barwick, Nada Perovic, Uwe von Gostomski
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Forum Stats:
Groups: 3
Forums: 24
Topics: 6218
Posts: 27266

 

Member Stats:
Guest Posters: 49
Members: 31901
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.