Hi,
I'm back with my little bug reporting tool and now I would like to know how I populate a form with values from a row in my excel sheet that i selected in a multicolumn textbox.
My "tool" works like this... The user opens the excel file and can choose one of two buttons, Add defect and Find defect. When the Add button is clicked Form1 is opened and the user fills in a number of fields which are then inserted into an excel sheet (same book though). Then there's the Find button. When the user clicks this button Form2 opens with a multicolumn textbox that displays some of the columns with some of the previously inserted information. Now I would like to be able to select one row and get Form1 populated with the values for that particular row. The user should then be able to change some of the values and the changes should be inserted back into the correct row in my excel sheet. How in the world do I do this??? Right now I just open my Form1 when I select a row and click an OK button. How do I get the values from my excel sheet back into my fields?I've tried to copy code from an example I found, but I can't get it to work.
My first form where I add my data
My second form where I have my multicolumn textbox and where I'm suppose to select a row and get Form1 displayed with all data for a particular row
As you probably can see from my code... I'm completely lost and I haven't got a clue what I'm doing.
I'm back with my little bug reporting tool and now I would like to know how I populate a form with values from a row in my excel sheet that i selected in a multicolumn textbox.
My "tool" works like this... The user opens the excel file and can choose one of two buttons, Add defect and Find defect. When the Add button is clicked Form1 is opened and the user fills in a number of fields which are then inserted into an excel sheet (same book though). Then there's the Find button. When the user clicks this button Form2 opens with a multicolumn textbox that displays some of the columns with some of the previously inserted information. Now I would like to be able to select one row and get Form1 populated with the values for that particular row. The user should then be able to change some of the values and the changes should be inserted back into the correct row in my excel sheet. How in the world do I do this??? Right now I just open my Form1 when I select a row and click an OK button. How do I get the values from my excel sheet back into my fields?I've tried to copy code from an example I found, but I can't get it to work.
My first form where I add my data
Code:
Private Sub UserForm1_Initialize()
Dim rIds As Range
Dim MaxId As Long
Set rIds = Worksheets("Systemtest").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
MaxId = Application.WorksheetFunction.Max(rIds)
With Me
.IdBox.Value = MaxId
Private Sub DateBox_Change()
DateBox = Format(Date, "yy/mm/dd")
End Sub
Private Sub HeadingBox_Change()
End Sub
Private Sub IdBox_Change()
' =IF(COUNTA(Systemtest[1]:Systemtest[1])=1,COUNTA(Systemtest[1]:Systemtest[1]),"""")
End Sub
Private Sub StatusBox_Change()
StatusBox.List = Array("New", "Open", "In Progress", "Fixed", "Closed", "Reopen", "Rejected", "Pending")
' StatusBox.Value = "New"
End Sub
Private Sub SeverityBox_Change()
SeverityBox.List = Array("Critical", "Major", "Normal", "Minor", "Cosmetic", "Improvement")
' SeverityBox.Value = "Normal"
End Sub
Private Sub EnvBox_Change()
EnvBox.List = Array("NLL", "JLL", "NLL/JLL", "Halland")
' SeverityBox.Value = "NLL"
End Sub
Private Sub SummaryBox_Change()
End Sub
Private Sub VersionBox_Change()
VersionBox.List = Array("3.5.aa.1", "3.5.aa.2", "3.5.aa.3", "3.5.aa.4", "3.5.ab.1")
' SeverityBox.Value = "3.5.aa.1"
End Sub
Private Sub SubsysBox_Change()
SubsysBox.List = Array("Ankomstreg (Ö,S)", "Diagnosreg", "Generella", _
"IVA", "Infektionsreg", "Integration", "Journal", "LAB", "Läkemedel", "Läkarintyg/utl", _
"Operation", "PAS Generella", "Pako", "Paramedicin", "Patient", "Remisser", "Röntgen", "System", _
"Tandvårdsadm", "Vårddok", "Vårdkontakt")
' SubsysBox.Value = "Generella"
End Sub
Private Sub FormBox_Change()
End Sub
Private Sub TesterBox_Change()
TesterBox.List = Array("ast", "bng", "dll", "esi", "ewalun", "frea", "jfn", "kata", "larb", "lln", "mem", "mhd", "mlm", "moae", "mwn", "ulwi")
' TesterBox.Value = "ast"
End Sub
Private Sub ResponsibleBox_Change()
ResponsibleBox.List = Array("ast", "dll", "esi", "frea", "hkn", "jfn", "kata", "larb", "lln", "mem", "mhd", "mlm", "moae", "mwn", "ulwi")
' ResponsibleBox.Value = "ast"
End Sub
Private Sub FixedVerBox_Change()
FixedVerBox.List = Array("3.5.aa.2", "3.5.aa.3", "3.5.aa.4", "3.5.ab.1", "3.5.ab.2")
' FixedVerBox.Value = "3.5.aa.2"
End Sub
Private Sub CommentsBox_Change()
End Sub
Private Sub ClosingBox_Change()
ClosingBox = Format(Date, "yy/mm/dd")
End Sub
Private Sub OKButton_Click()
' Make sure Systemtest is active
Sheets("Systemtest").Activate
' Determine the next empty row
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
' Transfer the information
Cells(NextRow, 1) = IdBox
Cells(NextRow, 2) = DateBox
Cells(NextRow, 3) = StatusBox
Cells(NextRow, 4) = ClosingBox
Cells(NextRow, 5) = HeadingBox
Cells(NextRow, 6) = SummaryBox
Cells(NextRow, 7) = CommentsBox
Cells(NextRow, 8) = TestspecBox
Cells(NextRow, 9) = SeverityBox
Cells(NextRow, 10) = EnvBox
Cells(NextRow, 11) = VersionBox
Cells(NextRow, 12) = SubsysBox
Cells(NextRow, 13) = FormBox
Cells(NextRow, 14) = TesterBox
Cells(NextRow, 15) = ResponsibleBox
Cells(NextRow, 16) = FixedVerBox
' Clear the controls for the next entry
IdBox.Text = ""
StatusBox.Text = ""
HeadingBox.Text = ""
SummaryBox.Text = ""
CommentsBox.Text = ""
SeverityBox.Text = ""
EnvBox.Text = ""
VersionBox.Text = ""
SubsysBox.Text = ""
FormBox.Text = ""
TestspecBox.Text = ""
' TesterBox.Text = ""
ResponsibleBox.Text = ""
FixedVerBox.Text = ""
ClosingBox.Text = ""
OptionUnknown = True
StatusBox.SetFocus
End Sub
Private Sub RegNewButton_Click()
End Sub
Private Sub CancelButton_Click()
Unload UserForm1
End Sub
My second form where I have my multicolumn textbox and where I'm suppose to select a row and get Form1 displayed with all data for a particular row
Code:
Private Sub UserForm_Initialize()
Dim Sh As Worksheet
Dim Rng As Range
Dim Cell As Range
Dim r As Integer
Set Sh = Worksheets("Systemtest")
With Sh
Set Rng = .Range("A1:A" & .Cells(.Rows.Count, 1).End(xlUp).Row)
End With
r = 0
For Each Cell In Rng
With Cell
ListBox1.AddItem .Value
ListBox1.List(r, 1) = .Offset(0, 1).Value
ListBox1.List(r, 2) = .Offset(0, 2).Value
ListBox1.List(r, 3) = .Offset(0, 4).Value
ListBox1.List(r, 4) = .Offset(0, 5).Value
ListBox1.List(r, 5) = .Offset(0, 7).Value
ListBox1.List(r, 6) = .Offset(0, 12).Value
ListBox1.List(r, 7) = .Offset(0, 14).Value
ListBox1.List(r, 8) = .Offset(0, 13).Value
ListBox1.List(r, 9) = .Offset(0, 15).Value
End With
r = r + 1
Next Cell
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub OKButton2_Click()
UserForm1.Show
Dim FirstId As String
Dim strFind As String 'what to find
Dim rSearch As Range 'what range to search
Dim fndA, fndB, fndC, fndD, fndE, fndF, fndG, fndH, fndI, fndJ, fndK, fndL, fndM, fndN, fndO, fndP As String
Dim head1, head2, head3, head4, head5, head6, head7, head8, head9, head10, head11, head12, head13, head14, head15, head16 'headings for list
Dim i As Integer
i = 1
Set rSearch = Systemtest.Range("a2", Range("a65536").End(x1Up))
Str.Find = Me.TextBox1.Value
With rSearch = Systemtest.Range
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
c.Select
'load the headings
head1 = Range("a2").Value
head2 = Range("b2").Value
head3 = Range("c2").Value
head4 = Range("d2").Value
head5 = Range("e2").Value
head6 = Range("f2").Value
head7 = Range("g2").Value
head8 = Range("h2").Value
head9 = Range("i2").Value
head10 = Range("j2").Value
head11 = Range("k2").Value
head12 = Range("l2").Value
head13 = Range("m2").Value
head14 = Range("n2").Value
head15 = Range("o2").Value
head16 = Range("p2").Value
With Me.ListBox1
MyArray(0, 0) = head1
MyArray(0, 1) = head2
MyArray(0, 2) = head3
MyArray(0, 3) = head4
MyArray(0, 4) = head5
MyArray(0, 5) = head6
MyArray(0, 6) = head7
MyArray(0, 7) = head8
MyArray(0, 8) = head9
MyArray(0, 9) = head10
MyArray(0, 10) = head11
MyArray(0, 11) = head12
MyArray(0, 12) = head13
MyArray(0, 13) = head14
MyArray(0, 14) = head15
MyArray(0, 15) = head16
End With
FirstId = c.Id
Do
'Load details into Listbox
fndA = c.Value
fndB = c.Offset(0, 1).Value
fndC = c.Offset(0, 2).Value
fndD = c.Offset(0, 3).Value
fndE = c.Offset(0, 4).Value
fndF = c.Offset(0, 5).Value
fndG = c.Offset(0, 6).Value
fndH = c.Offset(0, 7).Value
fndI = c.Offset(0, 8).Value
fndJ = c.Offset(0, 9).Value
fndK = c.Offset(0, 10).Value
fndL = c.Offset(0, 11).Value
fndM = c.Offset(0, 12).Value
fndN = c.Offset(0, 13).Value
fndO = c.Offset(0, 14).Value
fndP = c.Offset(0, 15).Value
MyArray(i, 0) = fndA
MyArray(i, 1) = fndB
MyArray(i, 2) = fndC
MyArray(i, 3) = fndD
MyArray(i, 4) = fndE
MyArray(i, 5) = fndF
MyArray(i, 6) = fndG
MyArray(i, 7) = fndH
MyArray(i, 8) = fndI
MyArray(i, 9) = fndJ
MyArray(i, 10) = fndL
MyArray(i, 11) = fndM
MyArray(i, 12) = fndN
MyArray(i, 13) = fndO
MyArray(i, 14) = fndP
i = i + 1
Set c = .FindNext(c)
End If
End With
'Load data into LISTBOX
Me.ListBox1.List() = MyArray
End Sub
Private Sub CancelButton2_Click()
Unload UserForm2
End Sub
Private Sub UserForm_Click()
End Sub
As you probably can see from my code... I'm completely lost and I haven't got a clue what I'm doing.