Consulting

Results 1 to 5 of 5

Thread: Change value of adjacent cell if field in form matches

  1. #1
    VBAX Regular
    Joined
    Feb 2014
    Location
    Ashford, Surrey, UK
    Posts
    64
    Location

    Change value of adjacent cell if field in form matches

    Hi all,

    I want to create a method of quickly updating a series of prices based on their product code. I have a form which pops up and asks for the product code and new price. This is the code I've written to do it, but no prices ever change.

    Sub PriceChange()
    
    
    Dim A As Integer, B As Variant, Cell As Range, TextBox1, TextBox2 As TextBox
        
        For Each Cell In Range("ProductCodes")
            If Cell.Value = UserForm1.TextBox1.Value Then
                Cell.Offset(0, 1).Value = UserForm1.TextBox2
            End If
        Next
        
        UserForm1.Hide
        MsgBox ("The pricing update has been carried out.")
    
    
    End Sub
    Could anyone enlighten me?

    Thanks,

    Jonathon

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try changing

        For Each Cell In Range("ProductCodes")
    to

        For Each Cell In Worksheets("whatever-the_sheet_is_called").Range("ProductCodes")
    and get rid of

    , TextBox1, TextBox2 As TextBox
    in the Dim statement
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Feb 2014
    Location
    Ashford, Surrey, UK
    Posts
    64
    Location
    Hi xld, unfortunately those changes didn't do anything. I don't think that the IF statement actually acts at all

    Edit: just tested it with some mock values in the macro (as opposed to in the form) and it does work, but it doesn't seem to be reading what's in the form.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Feb 2014
    Location
    Ashford, Surrey, UK
    Posts
    64
    Location
    Not really, sorry! It would take me ages to strip it. I modified the macro so it didn't require a form, which I'm happy with now. So, not to worry!

Posting Permissions

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