Results 1 to 6 of 6

Thread: Autofill and Reverse Autofill

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    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 )
    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
    Worksheet: Sheet1



    Autofile.xlsm:
    https://app.box.com/s/mt1c2xvdejjj6d3vjo6wkjyrdxrs98tm
    Last edited by DocAElstein; 07-04-2020 at 03:25 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. AutoFill Formula To The Last Row With Data
    By SaburaZera in forum Excel Help
    Replies: 2
    Last Post: 08-22-2014, 11:54 AM
  2. Need an Autofill VBA
    By mrprofit in forum Excel Help
    Replies: 12
    Last Post: 05-19-2014, 07:45 PM
  3. VBA Code To Autofill Formula In Every Nth Row
    By analyst in forum Excel Help
    Replies: 1
    Last Post: 12-23-2013, 05:51 PM
  4. Replies: 6
    Last Post: 12-23-2013, 04:07 PM
  5. Autofill the data based on non blank cell in next row?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 3
    Last Post: 11-29-2012, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •