I think this macro does what you want. I have not checked it thoroughly. I leave it to you to check thoroughly that it does all what you want.
If you have difficulty modifying it for your full range, then let me know and I will do it for you in a few days.
Code:Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo Bed If Application.Intersect(Target, Me.Range("C3:F5")) Is Nothing Then Exit Sub ' No overlap with the entry range, so exit sub ' Case1 If Not Application.Intersect(Target, Me.Range("C3:C5")) Is Nothing Then ' Column C entry If IsArray(Target.Value) Then Exit Sub ' more than one cell selected, but this procedute can only work on single cell entzries in column C If Len(Target.Value) <> 1 Then Exit Sub If InStr(1, ",A,B,C,D,E,", "," & Target.Value & ",", vbBinaryCompare) = 0 Then Exit Sub Dim PosS As Long: Let PosS = (InStr(1, ",A,B,C,D,E,", Target.Value, vbBinaryCompare) / 2) + 2 ' Row number in REFERENCE CHART for the corrsponding Sex Category Area values Let Application.EnableEvents = False ' This is to prevent the worksheet change in the next code line setting off this procedure again Let Target.Offset(0, 1).Resize(1, 3).Value = Me.Range("T" & PosS & ":V" & PosS & "").Value Let Application.EnableEvents = True ' Case2 ElseIf Not Application.Intersect(Target, Me.Range("D3:F5")) Is Nothing Then ' Entry in column D E or F If Target.Rows.Count <> 1 Then Exit Sub ' more than 1 row selected, but this procedure can only work on single row entries Dim arrSCA() As Variant: Let arrSCA() = Array("BOYGENURBAN", "BOYOBCURBAN", "BOYSCURBAN", "BOYSTURBAN", "GIRLGENURBAN") Dim TrgtRw As Long: Let TrgtRw = Target.Row Dim DEF As String: Let DEF = Me.Range("D" & TrgtRw).Value & Me.Range("E" & TrgtRw).Value & Me.Range("F" & TrgtRw).Value Dim Mtchres As Variant Let Mtchres = Application.Match(DEF, arrSCA(), 0) If IsError(Mtchres) Then Exit Sub ' no matching set of entries in columns D E and F Dim PosS2 As Long: Let PosS2 = Mtchres + 2 ' Row number in REFERENCE CHART for the corresponding Alpha Code Let Application.EnableEvents = False Let Me.Range("C" & TrgtRw & "").Value = Me.Range("S" & PosS2 & "").Value Let Application.EnableEvents = True Else End If Bed: ' just incase anything goes wrong, it is a good idea to make sure that things are turned back to normal Let Application.EnableEvents = True End Sub
I tried a few values and got these sorts of results
_____ Workbook: Autofill.xlsm ( Using Excel 2007 32 bit )
Worksheet: Sheet1
Row\Col B C D E F G H 2 S. No. Alpha Code Sex Category Area 3 1 E GIRL GEN URBAN 7 4 2 D BOY ST URBAN 5 3 B BOY OBC URBAN 6 4
Autofile.xlsm:
https://app.box.com/s/mt1c2xvdejjj6d3vjo6wkjyrdxrs98tm




Reply With Quote
Bookmarks