Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 29

Thread: Changing data selected in a UserForm

  1. #1
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location

    Changing data selected in a UserForm

    Hi Guys... I?m working in a project that I need to use a userform to change or replace data in a sheet dababase. I would like to use the same userform to view and change/replace this data using view/change button.

    Does anybody could help me??

    Please find below the file attached.
    Last edited by Petrogeo; 12-15-2006 at 11:53 AM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Petrogeo
    You can use UserForm_Initialize to read in data from the spreadsheet. You can also set a button to update amended data from the form to the spreadsheet. Here's a simple example
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location

    Question

    Thanks for response... good idea to insert the update button... but it didn?t work very well... first: the combobox "cboSeq" didn?t get all the values from the spreadsheet... So the update values are made just for the row selected.
    Any other idea?

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Apologies for not being psychic.
    What is the logic behind the combobox; why not just use a textbox?
    So the update values are made just for the row selected.
    I don't understand what you mean.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    Md, one of the reasons is because the "Seq" column on the spreadsheet could have equal values, for example: one "Seq" could be acquired in different days, different lines... etc..

    I?m sending the file with some modifications.. thanks

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You need to explain what you're trying to achieve. If seq is limited to the read in values, what happens if you need a new one? You also have repeated values in seq. How are you intending to make use of these?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location

    Question

    "Seq" numbers is not limited, I can enter new one on "imput Data" form. What I need to know is how could I modify Line numbers, Date, FSP... and apply this mofications on the same sequence (Seq)... pressing "view/update" button ???

    thanks in advance

  8. #8
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Use a unique number (the rowno) that you call for example Id_no. This Id_no can be used to search on (since it is unique). When you are on a form and want to change something we search on a row in column A for this unique number. When found, we select the whole row. When you change something, you could say something like
    ActiveCell.EntireRow.Cells(1, 1).Value = textbox1.Value
    ActiveCell.EntireRow.Cells(1, 2).Value = textbox2.Value
    ActiveCell.EntireRow.Cells(1, 3).Value = textbox3.Value[/VBA]
    To search a value (id_no) you could use this :[VBA]
          Dim Result As Variant
          Dim Lookvalue As Long      
          Result = Empty
    'xllastrow = function to look for last row
          With ActiveSheet.Range("a1:a" & xlLastRow)
       Lookvalue = TextBox1.Value 'value to look for
       Set Result = .Find(What:=Lookvalue, LookIn:=xlValues)
       If Not Result Is Nothing Then Result.Rows.EntireRow.Select Else Exit Sub
    End With
    'form to change the values in the row you just found
    Row_found_that_we_want_to_change.Show
    Charlize
    Last edited by Aussiebear; 04-13-2023 at 12:13 AM. Reason: Adjusted the code tags

  9. #9
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    Thanks Charlize,

    I will try to use your tips on my VBA... and change the TextBox "search" to a comboBox "selection". Do you think it?s possible??

    cheers

  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Don't dimension range variables as variants. Do not do this...

    Dim Result As Variant
    Instead, do it like this...

    Dim Result As Range
    HTH
    Last edited by Aussiebear; 04-13-2023 at 12:14 AM. Reason: Adjusted the code tags

  11. #11
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location

    Adding rows with data

    A modified version with an 'Add' to show you the idea behind the rowno. Values entered in seqno and cabosno are read in a combobox so you can use them again or fill in a new value. Try to add some values.

    When you click the button to view/add/change it will work starting from row 3.

    Charlize

  12. #12
    hello

    i whas looking for something simillar like this dbase like thing , i tested it but the update function doesn't seem to bee working on the cells that need to be updated ? am i missing something ?
    thanks for the help otherwise

  13. #13
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    Hi,

    I was testing the same function but it didn?t work either... I?m still trying to solve this problem... any other idea??

    thanks in advance

  14. #14
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Tried the update/edit button on my version (adapted version of mdmackillop) and for me it works. Only for seqno and date (I believe) but if you add the code for the rest of the values it will work. Have you tried changing seqno and date ? Watch your sheet when you push the button.

    Charlize

  15. #15
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    I?m working on this... now I have a reasonable results and I can change several values.

  16. #16
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location

    Question

    Does anybody know how to change the date format on the code?? mm/dd/yy to dd/mm/yy ????

  17. #17
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Is it an actual date? If it is an excel recognized date, just use the Format() function. Post your code if not.

  18. #18
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    The code is:

    Private Sub UserForm_Initialize()
    txtData.Value = Date
    End Sub
    How do i format date to dd/mm/yy ??
    Last edited by Aussiebear; 04-13-2023 at 12:15 AM. Reason: Adjusted the code tags

  19. #19
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    txtData.Value = Format(Date, "dd/mm/yy")
    Last edited by Aussiebear; 04-13-2023 at 12:18 AM. Reason: Adjusted the code tags

  20. #20
    VBAX Regular
    Joined
    Dec 2006
    Posts
    22
    Location
    Thanks Firefyrt....

Posting Permissions

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