Search row based on selected listitem

ldbuma

New Member
Joined
Nov 25, 2009
Messages
3
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?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top