+ Reply to Thread
Results 1 to 8 of 8

Validate product and automatically fetch price

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2014
    Location
    Oslo
    MS-Off Ver
    2010
    Posts
    8

    Red face Validate product and automatically fetch price

    In sheet 2 I have a column for `product` and a column for `price`. In sheet 2 I have a column of validation for `product`. When I select for example `Pants`, `price` should automatically come in the next column. However, it should also be possible to write `price` manually, therefore I need to do this with VBA.

    Skjermbildewfwqf.jpggssg.jpg


    Can anybody help please?
    Attached Images Attached Images

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Validate product and automatically fetch price

    Hi tepsjane!

    Welcome to the forum..

    Check this VBA..

    Test.JPG

    PS: We also have Print Screen button on keyboard..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Validate product and automatically fetch price

    It is not clear what column Product and Price are in for Sheet 1 so I will assumn column A and B respectively. The code placement will be within Sheet2 for the VBA Project.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        Target.Offset(, 1) = Sheets("Sheet1").Range("A:A").Find(What:=Target, LookIn:=xlValues, LookAt:=xlWhole).Offset(, 1)
    End If
    
    End Sub

  4. #4
    Registered User
    Join Date
    12-05-2014
    Location
    Oslo
    MS-Off Ver
    2010
    Posts
    8

    Re: Validate product and automatically fetch price

    Thanks for the reply. Is close to the target, but does not work 100%. Maybe I've done wrong? Attaching spreadsheets, maybe you can check this. Thank you in advance.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Validate product and automatically fetch price

    Of course it didn't work, I had bad information.

    This goes in Order Form Sheet:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        Target.Offset(, 1) = Sheets("Sheet2").Range("A:A").Find(What:=Target, LookIn:=xlValues, LookAt:=xlWhole).Offset(, 1)
    End If
    
    End Sub

  6. #6
    Registered User
    Join Date
    12-05-2014
    Location
    Oslo
    MS-Off Ver
    2010
    Posts
    8

    Re: Validate product and automatically fetch price

    Thank you. You have made my day, I'm very happy. Again, thanks for all your help.

  7. #7
    Registered User
    Join Date
    12-05-2014
    Location
    Oslo
    MS-Off Ver
    2010
    Posts
    8

    Re: Validate product and automatically fetch price

    Hello again. I have a small question with regard to the worksheet. I can overwrite cells for the price, but can not overwrite cells for product. Very nice if I can edit both product and price without error "Object variable or With block variable not set." Thanks for all your help

  8. #8
    Registered User
    Join Date
    12-05-2014
    Location
    Oslo
    MS-Off Ver
    2010
    Posts
    8

    Re: Validate product and automatically fetch price

    Hi
    I found a solution, used "On Error Resume Next" and everything seems very nice. Thanks again to you

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then
    On Error Resume Next
    Target.Offset(, 1) = Sheets("Sheet2").Range("A:A").Find(What:=Target, LookIn:=xlValues, LookAt:=xlWhole).Offset(, 1)
    End If

    End Sub

+ 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. Replies: 1
    Last Post: 07-24-2013, 12:13 PM
  2. In need of a formula or function that can validate a product ID
    By h2hinstalled in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-28-2013, 04:37 PM
  3. Excel 2007 : Product Name & Price
    By mortazkhoo in forum Excel General
    Replies: 1
    Last Post: 07-08-2010, 04:04 PM
  4. Product price with marges
    By Kayserili in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2007, 08:52 AM
  5. at, if statement with text, such as if(product), then (price)
    By Bob Phillips in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 07:05 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