+ Reply to Thread
Results 1 to 8 of 8

Macro help - finding and displaying cell values

  1. #1
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Macro help - finding and displaying cell values

    I have a question regarding a Macro that I am trying to make.

    What I have set up is a UserForm that I have made with two listboxes as well as a command button. The listboxes show information from 2 categories, and when you pick one of both options and hit the command button, it displays a few characteristics that each category has, like length and width. The trouble I'm having is I need to be able to find and display the dimensions of each object, however, the way I have been trying to accomplish this hasn't been working. I the method I used to find the row of the selected item is as follows

    Please Login or Register  to view this content.
    This method works, and it is stored in the above variables, and the columns for the width are the same for each category. The way I tried to find the value of the width was using this piece of code and it wasn't working.

    Please Login or Register  to view this content.
    I need to do the same process for the length, but I am not sure how to go about this.

    Any help is appreciated. Thank you!
    Last edited by JayEmTee91; 10-11-2011 at 08:04 AM. Reason: Solved

  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: Macro help - finding and displaying cell values

    You need to provide more information. What isn't working? Do you mean it gives you the wrong answer, or it gives you an error?

    Also, where is this code? Is it the code for the userform, or a worksheet, or something else?

    Can you attach your file?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: Macro help - finding and displaying cell values

    When I try to get the cell that contains the width data, using the cells(rowV1, 6).Value, my macro does not give any information. There are no errors, it does not return the value that I would like it to return. I'm a beginner to Visual Basic, so I'm not really sure what to do.

    All of the code was done in Visual Basic through Excel, and it's on the command button of the UserForm.

    I will attach the code.
    Last edited by JayEmTee91; 10-19-2011 at 01:50 PM.

  4. #4
    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: Macro help - finding and displaying cell values

    In this code
    Please Login or Register  to view this content.
    you are getting the value from column 6, which is F. That's GVWR, not width. Then you get a value from column 13, which is M, which is blank.

    You also seem to confusing the two worksheets in your code. Instead of activating a sheet, use explicit qualification for each cell reference.

    Also, you are using a MATCH function to look up the position of the selected item, but the ListIndex property of the list already tells you that. ListIndex starts using 0 as the first item so you have to add 1 to get the row number. Also you have a header row, so you have to add 1 again.

    You also use intermediate variables where they aren't really necessary. This sometimes make code more readable, but sometimes just makes it bigger.

    You seem to be loading the second listbox from the list of trailer GVWR. I think you meant to use the trailer name.

    One suggestion, which I didn't implement: You may want to create named ranges for the vehicle and trailer names. Then if you change the way your data is organized, you won't have to change the listbox range source.

    Here is how I would write this code, book is also attached:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: Macro help - finding and displaying cell values

    That works great. Thank you so much!

  6. #6
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: Macro help - finding and displaying cell values

    I could not get the way you suggested to work given my code, but the following code allows me to do what I want.

    With each click in the userform, the counter and all the information in the click is moved to another sheet called history, and since the information that is copied occupies 2 rows, i want it to skip a row and then continue onto the one after that. Each click stores history based on the number.

    The code that I have messes up on the first two clicks. The first click puts the items that were copied in the first spot I want, but then the second click overwrites the first clicks copy. The third click skips a line and copies the information correctly. I do not understand why that is. My code is below:

    This code is for the counter...
    Please Login or Register  to view this content.
    This code is for the copy command.
    Please Login or Register  to view this content.
    Any suggestions would be appreciated!

  7. #7
    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: Macro help - finding and displaying cell values

    With a problem like this you need to attach your whole workbook. I can't see what happens when you click a button.

    I could not get the way you suggested to work given my code....
    I am very puzzled by this seeing as though I didn't just make a suggestion. I took your workbook, fixed it, and then posted the completed solution. What did you post if it wasn't your code?

  8. #8
    Registered User
    Join Date
    10-10-2011
    Location
    Michigan
    MS-Off Ver
    2007
    Posts
    13

    Re: Macro help - finding and displaying cell values

    I apologize, I posted this is in the wrong thread. I meant to post it in my other thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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