+ Reply to Thread
Results 1 to 16 of 16

Finding similar tabs compared to data

  1. #1
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Finding similar tabs compared to data

    Hello all,

    I am having some trouble with my program and would really appreciate anyone's assistance on the matter.
    Please Login or Register  to view this content.
    This is currently my code and it works like I want except for one thing. There are instances where there are multiple names for the same part, ex. 1111A or 1111BA, and when the program runs into these parts that don't directly match the sheet name, 1111, it errors out. so is there anything I can add similar to a match function that would fix this problem? Thank you for your assistance.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    Look up the LIKE command. It will let you match a number of wildcard combinations.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    So should that be located in the code when defining the strDestinationsheet?

    Please Login or Register  to view this content.
    Like this? I did that and now I am getting an out of range error when it gets to the
    Please Login or Register  to view this content.
    part of the code.

    I really appreciate the input.

  4. #4
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    So should that be located in the code when defining the strDestinationsheet?

    Please Login or Register  to view this content.
    Like this? I did that and now I am getting an out of range error when it gets to the
    Please Login or Register  to view this content.
    part of the code.

    I really appreciate the input.

  5. #5
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    I have been trying multiple methods on how to get similar part names to be pulled but am having no luck. I tried the Like command as shown above, I tried an "And" command as well to include the ActiveCell.Value And "*" , but every time I change the strDestinationSheet line the Sheets(strDestinationSheet).Visible= True section faults out. Is there some obvious thing I am missing or do I just not have everything defined correctly. I would really appreciate any input on this problem.

    Thank you

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    My apologies for being late to respond. I'm catching up from "snow days."

    It would help a lot if you can include a workbook to go along with the code. Also I notice that you are using activecell and select a lot in your code. There are better ways of doing this. If you don't mind, I'll rewrite it with lots of comments explaining why I'm doing things.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    I would really appreciate any help I can get, I have been scouring the internet looking for something that would help me figure out what
    I needed to add but have had minimal luck. Attached is a similar workbook where the first sheet is the total list of data and the following
    sheets are where I want the data to be sent to. When running the code I watched and it seemed like something could be faster I just didn't
    have the skills to accomplish that so rewriting it would be an immense help.

    Thank you again for the assistance.
    Attached Files Attached Files

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    Here is what I think you want.

    A couple of comments on the code. Whenever possible, avoid using active anything such as active sheet or active cell. Quite often your idea of what’s active and Excel’s idea of what is active may be two different things. It is always best to tell Excel where you want it to be.

    Also, there generally is not a good reason to select anything. Selecting something only slows the code down. When the macro recorder comes up with
    Please Login or Register  to view this content.
    You can usually replace it with
    Please Login or Register  to view this content.
    Having said all this, there are cases such as when working with charts, where you have to select the item and then work with the active item such as ActiveChart. These are exceptions.

    There are several different ways to reference sheets in the code. You can use the sheet name Sheets(“SheetName”) or its position Sheets(2). Another way is to declare a variable as type worksheet and set it to “point” at the sheet: Set shD = Sheets(“Master Sheet”).

    One advantage of the pointer method is that it saves typing. Instead of using Sheets(“Master Sheet”) everywhere, you can just use shD.

    There is also a subtle difference between the pointer and explicit versions. The pointer method knows which workbook the sheet is in. This comes in handy when you start working with multiple workbooks. So it’s a good habit to get into.

    We are only working with one workbook here so the pointer method really isn’t necessary, but I like the shortcut instead of doing all the typing.

    Also I try to use a naming convention whenever I can. In this code, anything ending in S has to do with the source sheet, and anything ending in D has to do with the destination sheet.

    I make use of an external function to get the matching sheet name. I could have embedded the code into the main subroutine, but I try to make my code as modular as possible. You’ll notice a small subroutine called test. By separating the GetSheet Function into its own self-contained piece, I was able to test it out without running the full code.

    Also, in the future, if you ever have to do a partial match of a string to a sheet name, you can lift this piece of code in its entirety.

    The GetSheet Function is an example of a user defined function. UDFs usually take arguments and return a value. This function makes use of the LIKE operator to see if the Part is a match for a sheet name. the sh.Name & “*” will match anything that begins with the sheet name and has anything or nothing following it. For more information on LIKE, see https://msdn.microsoft.com/en-us/library/swf8kaxw.aspx.

    I hope I put enough comments in the code so it’s understandable. If not, ask!

    I removed all the data on sheets 1 and 2 and saved the RAND() measurements as fixed values. I did this for the purposes of QA.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    I think I am following what you are doing, and this is definitely something I would need to work up to making myself, but I don't think it is pulling part numbers with similar names. Initially I ran your code and I kept getting "Macros are not enabled on this document" even though it is a Macro enabled file. When I tried to bring the code over anyway to the full file I got a Run-time error '1004' saying I cannot move a part of a pivotTable report. When debugged
    Please Login or Register  to view this content.
    is highlighted. I got it eventually to work on the file you sent me after adding a shortcut instead of trying to run it in the VBA window but I don't think it is pulling all "1" parts still. Maybe I am missing something but any input would be amazing.

    Thank you for all your help

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    I don't know where you are getting
    Please Login or Register  to view this content.
    That's not even part of my code.

    As for the macros are not enabled: just because a file *can* have macros doesn't mean that they are enabled. Whether macros get enabled depends on your Trust Center Settings.

    Also there a no pivot tables in the worksheet. I just downloaded the workbook and looked at it. Your comments led me to believe that I must have uploaded the wrong workbook.

  11. #11
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    My apologies, I think I ran a code that was similarly named to yours and that was the problem. I still am having problems with getting parts with similar names to the sheet name, like "1A", I know you said using the like command but I do not see that anywhere. I also tried to add part numbers to the original worksheet and the code did not pull these changes. Sorry for all the questions but I really do appreciate you helping me.

    Sorry again, so I ran the code again and it pulls the copies like I wanted, thank you again, but if it runs to a part that doesn't have a sheet with a similar name it stops completely. Is there any workarounds for this because I don't know exactly what numbers are there and what are not.
    Last edited by Jacobg38; 01-12-2017 at 11:30 AM. Reason: Mistake

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    This is the code you should be running.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    Alright yes this the code I am running and it works perfectly for the parts that it runs for, the last question I have about it is that when it hits a part that does not have a matching sheet it stops. Is there anyway to prompt it to continue through the part list?

    Thank you again for all the help.

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    Here is the code with the modification of the msgbox function. It now looks for an answer, and either exits or jumps to the next row to be processed depending on your answer.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-29-2016
    Location
    wisconsin
    MS-Off Ver
    Office 2010
    Posts
    20

    Re: Finding similar tabs compared to data

    Thank you so much. If I could give you more reputation I would, this is exactly what I have been trying to do for the better part of a week and I have been just hitting a wall. I will mark this thread as solved and hope it helps other people as well. Like I said before, thank you immensely for your help I could not have done it otherwise.

  16. #16
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Finding similar tabs compared to data

    You are welcome. It helps a lot that you were able to define the requirement rather clearly.

+ 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] Finding partial text matches compared to a range
    By grifta67 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-17-2014, 04:38 PM
  2. Replies: 1
    Last Post: 04-30-2014, 05:49 PM
  3. [SOLVED] ListBox. Finding the index of the compared row
    By aaronkoh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-29-2012, 12:58 AM
  4. Replies: 3
    Last Post: 05-28-2011, 01:43 PM
  5. a similar convention for tabs/wksts as in for R[1]C[1]?
    By JimTobin2 in forum Excel General
    Replies: 1
    Last Post: 08-23-2005, 10:05 PM
  6. Finding similar data or numbers in two columns
    By sayemasof in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-01-2005, 04:05 PM
  7. Sum similar concepts found in different tabs
    By hochedez in forum Excel General
    Replies: 5
    Last Post: 03-29-2005, 09:26 AM

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