4

screeshot of the excelHi i need to get column of a cell with the text as ACTION.

My current code is as below.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim actionColName As String
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
  Application.EnableEvents = False
  newVal = Target.Value
  Application.Undo
  oldVal = Target.Value
  Target.Value = newVal
  If Target.Column = 3 Then
    If oldVal = "" Then
      'do nothing
      Else
      If newVal = "" Then
      'do nothing
      Else
      Target.Value = oldVal _
        & "+ " & newVal
      End If
    End If
  End If
End If

exitHandler:
  Application.EnableEvents = True
End Sub

In the above code there is a condition as below If Target.Column = 3 Then

Instead of hard coding the value with 3 i would like to apply this logic for the complete column which contains the value ACTION in one of its cell in that column.

5
  • Can you pls post a sample file Commented Mar 18, 2013 at 11:22
  • I have posted the sample file Commented Mar 20, 2013 at 5:28
  • where is the sample file? Commented Mar 20, 2013 at 6:23
  • i have attached the screenshot.The requirement is that if i select two values from dropdown then two values will be added to cell with "+".Suppose if try to edit the cell with some new value which is not in the list then i m facing the issue.The result is like the second cell in the attached sheet.The values are getting replicated.I did not find any way to add the file,hence i added screenshot. Commented Mar 20, 2013 at 11:25
  • @bredttdj Any pointers for the solution Commented Apr 3, 2013 at 9:05

1 Answer 1

8

Use a Find to determine the (first) column containing Action

Sub GetAction()
Dim rng1 As Range
Set rng1 = ActiveSheet.UsedRange.Find("Action", , xlValues, xlWhole)
If Not rng1 Is Nothing Then
MsgBox "Found in column " & rng1.Column
Else
MsgBox "Not found", vbCritical
End If
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working.Could you please let me know how to edit the values in the dropdownlist on the fly instead of updating the list the in the excel?
Thanks its working.The problem i am facing is that i am applying the above logic on particular column.That Column's each cell is a drop down.For the first time i will select one value from dropdown and secondtime if i select other value in that dropdown from the same cell then the new value will appended with "+" symbol with the existing value.while adding the second value.Example i have selected a value "one" from the drop down.and if i want to add a new value something like "THOUSAND" to the drop down on the fly then i am seeing as one+one+THOUSAND instead of one+THOUSAND.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.