+ Reply to Thread
Results 1 to 4 of 4

VBA Macro Lookup sheet not there

  1. #1
    Registered User
    Join Date
    10-06-2021
    Location
    Ohio,USA
    MS-Off Ver
    97 - current
    Posts
    4

    VBA Macro Lookup sheet not there

    Hi everyone,

    I have attached four files. Report example is a report I receive monthly and don't do anything with besides changing the name. The script help word doc is actually a VBScript, but I pasted the code for it in a word doc as VBScript is an invalid file type. Template Help is the excel file the script runs and inside it are two macros. The final output is the Example file.

    If you look at the Template Help file you will see a Lookup Sheet that Column Y in the Example file references. The issue I am having is in the Example File the Lookup Sheet is no longer there, therefore all of column Y will return "misc" because that's the default false value.

    What I want is that lookup sheet to be in the Example file so that issue does not occur anymore.

    I am not sure what I added or what I am missing in the Macro(s) that causes the sheet to not appear.

    Any help would be greatly appreciated.

    Thank you
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Macro Lookup sheet not there

    The naming convention you are using for variables makes it difficult to read your code (wbBook1, wbBook2, wsSheet1, wsSheet2). Best practice is to make variable names meaningful, like wbTemplate and wbReport. Once I figured that out I was able to make this suggestion. Add the line of code shown in red. Your code is very specific to your environment (Outlook folders, file directory) and it would have taken too much time for me to set up a test, but you should be able to test this pretty quickly.
    Please Login or Register  to view this content.
    Also you declare and set but never use the variable misc. It is not needed.

    You seem to declare variables but you should also use Option Explicit and require declarations. Doing so prevents a lot of bugs and runtime errors.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Macro Lookup sheet not there

    One other thing: I don't see why you are using a standalone VBScript file to kick this off. It would be simpler to just open the template file, and add a Workbook_Open sub to automatically run the macro when the workbook is opened.

  4. #4
    Registered User
    Join Date
    10-06-2021
    Location
    Ohio,USA
    MS-Off Ver
    97 - current
    Posts
    4

    Re: VBA Macro Lookup sheet not there

    Thank you very much for the response. I agree with all that you said about best practice. I recently started working at this company and this is old code from the previous employee. I planned to fix some things up and all, but I am unfamiliar with VBA and it's important to get these reports running ASAP.

    Again, thank you for taking the time to help me. I am going to give it a try

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to lookup in other sheets based on cell as a sheet name
    By umberto79 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-23-2021, 09:21 AM
  2. [SOLVED] Macro to lookup a value in a Sheet and find that value in another sheet and Copy paste
    By Khalid.Noor in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-11-2018, 02:59 PM
  3. Macro to lookup data monthwise and aggregate the value in a new sheet
    By yemnirmal in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-13-2015, 05:36 AM
  4. [SOLVED] Excel Macro to lookup sheet name with a range of cells and paste in the reference sheet
    By mishaq in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2013, 02:55 PM
  5. Macro to move to Sheet/cell based on lookup
    By kingofbeans in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2013, 01:18 PM
  6. macro to update sheet, lookup value and delete ranges
    By Ralem in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-18-2011, 12:24 PM
  7. Macro to Lookup and Output to new sheet
    By Ray789 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-31-2010, 06:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1