PDA

View Full Version : Find and Replace VBA using Userforms



chardy1983
12-04-2015, 05:07 AM
Hi all,

I have attached the spreadsheet I am working through. I have completed must of the VBA I require, however, I am stuck on the macro to amend a PO number.

Once the PO book has open PO's, I have a button, which enables the user to amend one of the generated PO. The way I have gone about this is, to bring up a user form to type in the PO number that needs amending, this will then bring up the amendment form.

I cannot seem to find any VBA code which can find the PO number and then replace with details from amendment userform.

Can anyone help?

SamT
12-04-2015, 09:32 AM
Form Code

Module Level Variable
Dim PORow As Long


Private Function LetPORow()
PORow = Sheets("Purchase Orders").Range("D:D").Find(TextBox8.Value).Row
End Function

Code to fill Controls
Dim PORecord As Range

Set PORecord = Sheets("Purchase Orders").Rows(PORow)
With PORecord
txtSuppliers = .Cells(5)
txtEstValue = .Cells(6)
'Etc

If it were me, I would just use one UserForm for all the Work. If in Create PO Mode, Show a Label or TextBox with the new PO number. If in Amend or Edit mode, Show a ListBox filled with existing PO numbers.

With the ListBox, PORow = ListBox.TopIndex + 19
Or PORecord = Sheets("Purchase Orders").Range("D" & ListBox.TopIndex + 19 & ":N" & ListBox.TopIndex + 19), then
With PORecord
txtSuppliers = .Cells(1)
txtEstValue = .Cells(2)
'Etc