+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    04-21-2009
    Location
    Illinois, US
    MS-Off Ver
    Excel 2007
    Posts
    21

    Search Sheet2 Column A For Value In Textbox On Sheet1 Then Offset Right By 1-5 Column

    Having trouble with a a macro. I have a search function that works just fine. It pulls information from Sheet2 and places the data (which will always be integers) in 5 cells on Sheet1.

    My problem is this: I have added buttons to the right (of the cells that hold the data on Sheet1) which needs to increment or decrement the left-most respective values up or down by one... which I can do but the hard part for me is...

    I then need to search in column A to find the value in the textbox/searchbox field and when found, I need to offset to the right (columns B, C, D, E, or F depending on the "Service n"). When offset and the cell is found, I need to update this value with the newly updated value created by clicking the up or down button (basically adding or subtracting 1 from this cell).

    Essentially, this is used to update a product SKU quantity. When one SKU is sold, I have the "Down" button there to update the inventory amount so I enter the SKU, Press Search, then find the service I want to decrement, press the "Down" button to the right when a SKU is sold, and it would decrement that SKU quantity on Sheet2 by 1 for that particular service.

    I hope I've explained it thoroughly. I'll send $5 to the first person's Paypal that can figure this out. I'm sure it's simple and I'm overlooking something. I told my girlfriend I could figure this out but I need some help fellas (and ladies)!


    If you have a minute, please have a peek at my attached Excel document for a clear idea of what I mean.
    Attached Files Attached Files
    Last edited by sweetrevelation; 11-07-2009 at 06:55 PM.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,815

    Re: Search Sheet2 Column A For Value In Textbox On Sheet1 Then Offset Right By 1-5 Co

    I believe that you can do this much more simply.

    Your Down sub can be

    Code:
    Sub Down_Service1()
        Range("C9") = Range("C9") - 1
    End Sub
    On the Sheet1 tab in the VBA editor add the following. You will need to create the other up and down versions of this.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim TargetRow As Integer
    If Application.CountIf(Sheets("Sheet2").Columns(1), TextBox1.Value) = 1 Then
        TargetRow = Sheets("Sheet2").Columns(1).Find(TextBox1.Value).Row
    Else
        MsgBox "Unknown item"
        Exit Sub
    End If
    'repeat the next three lines to deal with the remaining columns
    If Target.Address = "$C$9" Then
        Sheets("Sheet2").Cells(TargetRow, 2) = Target
    End If
    
    
    
    
    End Sub
    I hope that this gets you started.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    04-21-2009
    Location
    Illinois, US
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Search Sheet2 Column A For Value In Textbox On Sheet1 Then Offset Right By 1-5 Co

    Thank you mrice! I definitely agree your method of adding and subtracting 1 was much better haha. I had it copying and pasting values here and there one cell to another... I just didn't know how the visual basic to do this.

    I can't thank you enough. I modified the spreadsheet and it is now pretty awesome. I didn't want to add buttons to have to manually update the total column. I would rather have some kind of change event where when one of the five service column numbers change, it reduces or increases the total column row for that sku + or - 1. Since I don't know how to do that, I just added buttons.

    I really appreciate your help. PM me with your Paypal email. Attached is the final version of what I came up with if in case anyone ever stumbles across this post.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7
    Posts
    1,958

    Re: Search Sheet2 Column A For Value In Textbox On Sheet1 Then Offset Right By 1-5 Co

    I've modified your workbook a little:
    Attached Files Attached Files
    ---
    Ben Van Johnson

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.2.0