I have a program in excel that allows me to do analysis/summarize data on one form by searching for terms through the use of drop down lists using data validation. I would like to be able to select multiple factors and have those selections inserted into a different column with each selection in a different row. I am able to do that with the following code adapted from the contextures website:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo exitHandler
Dim rngDV As Range
Dim lRow As Long
Dim lCol As Long
Dim cRow As Long
lCol = Target.Column 'column with data validation cell
If Target.count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Select Case Target.Column
Case 10
If Target.Offset(0, 18).Value = "" Then
lRow = Target.Row
Else
lRow = Cells(Rows.count, lCol + 18).End(xlUp).Row
End If
Cells(lRow, lCol + 18).Value = Target.Value
End Select
End If
exitHandler:
Application.EnableEvents = True
End Sub
My data validation list consists of jobs: Welder, Mechanic, and Janitor. (and many other fields)
If Welder is selected, this places Welder in another column (column 18). If it is selected again, then it gets inserted into the same column and row below it. My problem is, if I were to select Welder twice, I would like it to remove the "Welder" from the column, rather than placing another instance of it in there.
I have a decent amount of experience coding in R, but very little in VBA, and writing loops are very foreign for me. I have a general strategy how I might approach this sort of problem in R, but it will do me no good in there
. Thanks in advance for your time,
Lucas Smith
Bookmarks