• 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

How to generate whole table of values using code for VLookUp?|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / How to generate whole table of values using code for VLookUp?|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 & MacrosHow to generate whole table of valu…
sp_PrintTopic sp_TopicIcon
How to generate whole table of values using code for VLookUp?
Avatar
Stephanie Lim
Member
Members
Level 0
Forum Posts: 7
Member Since:
July 4, 2018
sp_UserOfflineSmall Offline
1
July 19, 2018 - 6:20 pm
sp_Permalink sp_Print

Hi!

Basically I'm trying to do something similar to that of Example 3 given in the below link: https://www.exceltrick.com/for.....es-in-vba/

The only difference is that the table (equivalent to 'Employee Table 1') I'm comparing to is on another worksheet. 

I used the code given in the link above but modified the code slightly to suit my purposes. 

Here is my code:

Sub Classify()

''copies over Product Type from hidden 'Product Codes' tab

''uses VLookup function

On Error Resume Next

Dim Pdt_Row As Long

Dim Pdt_Clm As Long

Sheets("P1").Select

finalrow = Cells(rows.Count, "A").End(xlUp).Row

Table1 = Worksheets("P1").Range("A14:A" & finalrow) ''Product Codes Column

Table2 = Worksheets("Product Codes").Range("A11:J397") ''Range of Product Types

Pdt_Row = Worksheets("P1").Range("E14").Row 

Pdt_Clm = Worksheets("P1").Range("E14").Column

For Each Cell In Table1

Worksheets("P1").Cells(Pdt_Row, Pdt_Clm) = Application.WorksheetFunction.VLookup(Cell, Table2, 10, False)

Pdt_Row = Pdt_Row + 1

Next Cell

End Sub

However, everytime I run the code, it will stop after a few lines. For example, say there are 100 product codes. The code will run for the first 20 product codes and identify the product name correctly for the first 20 codes. However, it stops there and does not continue.

I can't figure out what's the problem. 

Would appreciate some help here, thanks so much!

Avatar
Stephanie Lim
Member
Members
Level 0
Forum Posts: 7
Member Since:
July 4, 2018
sp_UserOfflineSmall Offline
2
July 20, 2018 - 12:17 pm
sp_Permalink sp_Print sp_EditHistory

Hi Sunny,

Pls refer to this sample worksheet.

Basically, when I click on the button 'Identify Product Type' in the 'Data' tab, I want to identify the Product Type each product code is linked to. This information can then be obtained from the 'Pdt Codes' tab.

However when I run the macro 'Classify', it will only do so up to B48. From B49 onwards, the code does not work.

How do I solve this problem?

Thanks!

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
3
July 20, 2018 - 3:42 pm
sp_Permalink sp_Print

Hi Stephanie

The VLOOKUP is unable to locate the codes 1010 to 1050 from your Pdt Codes sheet.

This is because these codes in the Data sheets are TEXT while those in the Pdt Codes sheet are NUMBERS.

Just change these codes in Pdt Codes to TEXT by putting a single quote in front of them like what you did for 0010 to 0997.

 

Use On Error Resume Next with care as it will ignore errors (like the VLOOKUP error you encountered) and continue to process.

Just try removing/commenting this line and run your code on your original file and you will see what I mean.

Hope this helps.

Sunny

Avatar
Stephanie Lim
Member
Members
Level 0
Forum Posts: 7
Member Since:
July 4, 2018
sp_UserOfflineSmall Offline
4
July 24, 2018 - 12:18 pm
sp_Permalink sp_Print

Hi Sunny,

That works. 

Thank you!

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
5
July 24, 2018 - 5:10 pm
sp_Permalink sp_Print

Thanks for your feedback.

Glad to know it is working for you.

Sunny

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Mynda Treacy, Shanna Henseler, Stacy Culpepper
Guest(s) 8
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:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27237

 

Member Stats:
Guest Posters: 49
Members: 31889
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.