Populate if Specific Text found

The Animal

Active Member
Joined
May 26, 2011
Messages
449
Hi
Maybe someone can point me in the right direction.
I have a tab that I am using as a key (Award Abbrev) that I want to use to populate cells in another tab in the same workbook (Staff Details)
I have created specific text in I2:I60 in "Award Abbrev" that on the corresponding row has values in R,U,X,AA.
On the "Staff Details" tab if the specific text is entered in the I column of that row, then the data that is found in R,U,X,AA in "Award Abbrev" will the populate in R,U,X,AA in Staff Details.
Any help would be great
Thanks Stephen
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
In sheet "Staff Details" code put
Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
Const InCol As String = "I"
Dim InColInt As Integer
Const OutCol As String = "R/U/X/AA"
Const WsRefName As String = "Award Abbrev"
Dim WS As Worksheet
Dim V
    InColInt = Cells(1, InCol).Column
    If (Target.Column <> InColInt) Then Exit Sub
    For Each V In Split(OutCol, "/")
        Cells(Target.Row, V) = SearVal(Target.Value, V)
    Next V
End Sub

in a module put
You will adjust Constante as needed
Code:
Option Explicit
Function SearVal(ByVal WkVal, ByVal OutWkCol As String) As Variant
Dim WS As Worksheet
Dim WkRg As Range
Dim F
Const WsName As String = "Award Abbrev"
Const WkRgAdd As String = "I2:I60"


    SearVal = ""
    Set WS = Sheets(WsName)
    Set WkRg = WS.Range(WkRgAdd)
    With WkRg
    Set F = .Find(What:=WkVal, After:=.Cells(1, 1), LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlRows, SearchDirection:=xlNext, _
            MatchCase:=False)
    End With
    If (F Is Nothing) Then Exit Function
    Application.EnableEvents = False
    SearVal = WS.Cells(F.Row, OutWkCol)
    Application.EnableEvents = True


End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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