Hi all,
I am trying to fill cells based on info that is entered and selected in a VBA form. The form contains a textbox to enter a value (newEntry), this value will be copied to the cell at the end of the list in row A of sheet2 ('flightspecific'). The form also contains 4 listboxes that will each be filled by a name range. These nemed ranges are defined in sheet1 ('Overview') and are also in sheet2 in column 2.
Now I want to fill the cells that are according specified selections in the form in sheet2 with "y". So the the row of the textbox and the column of the selections in the listboxes need to be 'extracted' and combined to fill that cell with "y". for example if the value 2012 is entered in the textbox and will be copied to A13 and the 1st and 3rd entry in listbox 1 are selected, which are in C2 and E2, I want to have C13 and E13 filled with "y".
At this moment I have the following (from the internet, because I am a very basic skilled vba user):
Dim DMIC_item As Long
For DMIC_item = 0 To DMIC_steps.ListCount - 1
If DMIC_steps.Selected(DMIC_item) = True Then
Dim FindStringC1 As String
Dim RngC1 As Range
FindStringC1 = DMIC_steps.Selected(DMIC_item)
If Trim(FindStringC1) <> "" Then
With Sheets("flightspecific").Range("2:2")
Set RngC1 = .Find(What:=FindStringC1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
Else
MsgBox "Nothing found"
End If
Dim FindStringR1 As String
Dim RngR1 As Range
FindStringR1 = newEntry
If Trim(FindStringR1) <> "" Then
With Sheets("flightspecific").Range("A:A")
Set RngR1 = .Find(What:=FindStringR1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not RngR1 Is Nothing Then
Sheets("flightspecific").Cells(RngR1.Row, RngC1.Column).Value = "y"
Else
MsgBox "Nothing found"
End If
End With
End If
End If
This returns the correct row from the newEntry, but I can't get the correct column based on the selection from listbox DMIC_steps.
Could anybody please help me?
I am trying to fill cells based on info that is entered and selected in a VBA form. The form contains a textbox to enter a value (newEntry), this value will be copied to the cell at the end of the list in row A of sheet2 ('flightspecific'). The form also contains 4 listboxes that will each be filled by a name range. These nemed ranges are defined in sheet1 ('Overview') and are also in sheet2 in column 2.
Now I want to fill the cells that are according specified selections in the form in sheet2 with "y". So the the row of the textbox and the column of the selections in the listboxes need to be 'extracted' and combined to fill that cell with "y". for example if the value 2012 is entered in the textbox and will be copied to A13 and the 1st and 3rd entry in listbox 1 are selected, which are in C2 and E2, I want to have C13 and E13 filled with "y".
At this moment I have the following (from the internet, because I am a very basic skilled vba user):
Dim DMIC_item As Long
For DMIC_item = 0 To DMIC_steps.ListCount - 1
If DMIC_steps.Selected(DMIC_item) = True Then
Dim FindStringC1 As String
Dim RngC1 As Range
FindStringC1 = DMIC_steps.Selected(DMIC_item)
If Trim(FindStringC1) <> "" Then
With Sheets("flightspecific").Range("2:2")
Set RngC1 = .Find(What:=FindStringC1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
Else
MsgBox "Nothing found"
End If
Dim FindStringR1 As String
Dim RngR1 As Range
FindStringR1 = newEntry
If Trim(FindStringR1) <> "" Then
With Sheets("flightspecific").Range("A:A")
Set RngR1 = .Find(What:=FindStringR1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not RngR1 Is Nothing Then
Sheets("flightspecific").Cells(RngR1.Row, RngC1.Column).Value = "y"
Else
MsgBox "Nothing found"
End If
End With
End If
End If
This returns the correct row from the newEntry, but I can't get the correct column based on the selection from listbox DMIC_steps.
Could anybody please help me?