ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Event Procedure again (https://www.excelbanter.com/excel-programming/322209-event-procedure-again.html)

Paul Johnson[_2_]

Event Procedure again
 
My last post was not so clear, as the formats were removed.

What I am trying to do is:

Write an event procedure, upon entering a "1" in a field, this matches the
column header against a corresponding set of data all on one row, and for
every match returns a formula on the same row as the 1 entered in the column
the match happened.
My Match headers are A,B,C, etc.
I hope this is clearer.
Many thanks for your help.
Paul



Tom Ogilvy

Event Procedure again
 
This assumes the A A A B C C C E 0
is in row 1 starting in F1

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, cell As Range
Dim rw As Range
If Target.Count 1 Then Exit Sub
If Target.Value = 1 Then
Application.EnableEvents = False
On Error GoTo ErrHandler
sTarget = Target.Offset(-1, 0).Value
rw = Target.Row
Set rng = Range("F1:N1")
For Each cell In rng
If cell.Value = sTarget Then
Cells(rw, cell.Column).Formula = "=Trunc(rand()*100+1)"
End If
Next
End If
ErrHandler:
Application.EnableEvents = True
End Sub

Right click on the sheet Tab, select view code and paste in the code.
Replace my formula with whatever formula you want.

--
Regards,
Tom Ogilvy


"Paul Johnson" wrote in message
...
My last post was not so clear, as the formats were removed.

What I am trying to do is:

Write an event procedure, upon entering a "1" in a field, this matches the
column header against a corresponding set of data all on one row, and for
every match returns a formula on the same row as the 1 entered in the

column
the match happened.
My Match headers are A,B,C, etc.
I hope this is clearer.
Many thanks for your help.
Paul






All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com