Results 1 to 6 of 6

Thread: Autofill and Reverse Autofill

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,458
    Rep Power
    10
    Hi
    _ 4.
    This is easy, simply convert the Target.Value to UCase(Target.Value) , and use that converted character in place of Target.Value
    ( If the Target.Value is already uppercase, then UCase(Target.Value) will not error - Target.Value will just stay as it is )



    _ 2. And 3.
    This is not difficult, but need s some juggling around with code lines
    Two similar code sections are needed

    _1. This is a bit more difficult. It is rather unusual not to have a range of the required LookUp information somewhere
    This information must come from somewhere.
    The most simple solution would be to have that range somewhere
    For now , I have put the information on a second worksheet. And made a minor change to the macro to reference that worksheet
    If this is not acceptable, then I can put the information somewhere else, such as in the macro itself.




    So here is my next solution for you.
    Once again for now, for clarity and simplicity, I have limited it just to a few rows

    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 procedure can only work on single cell entries in column C
            If Target.Value = "" Then 'This would be a cleared cell ( deleted value )
             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 = ""  '   If I delete the Alpha Code from a cell (for example C3), the corresponding range (D3:F3) should be empty/deleted automatically.
             Let Application.EnableEvents = True
            ElseIf Len(Target.Value) <> 1 Then Exit Sub ' we have an entry , but it is invalid
            Else
            End If
        Dim UcsTgtVl As String: Let UcsTgtVl = UCase(Target.Value)
            If InStr(1, ",A,B,C,D,E,", "," & UcsTgtVl & ",", vbBinaryCompare) = 0 Then Exit Sub
            Dim PosS As Long: Let PosS = (InStr(1, ",A,B,C,D,E,", UcsTgtVl, 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 = ThisWorkbook.Worksheets("REFERENCE CHART").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.Columns.Count = 1 Then
                If Target.Value = "" Then 'This would be a cleared cell ( deleted value )
                 Let Application.EnableEvents = False ' This is to prevent the worksheet change in the next code line setting off this procedure again
                 Let Me.Range("C" & Target.Row & "").Value = ""  '  If I delete any one cell value from the range (for example D3:F3), the corresponding Alpha Code (C3) should be deleted automatically. It means, the Alpha Code should be appear only if all the three cells in the corresponding range (for example D3:F3) are filled. Otherwise, the Alpha Code should be disappear/deleted.
                 Let Application.EnableEvents = True
                 Exit Sub
                Else
                End If
            ElseIf Target.Rows.Count <> 1 Then Exit Sub ' more than 1 row selected, but this procedure can only work on single row entries
            Else
            End If
        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
    Alan




    Share ‘Autofill.xlsm’ : https://app.box.com/s/mt1c2xvdejjj6d3vjo6wkjyrdxrs98tm
    ( Macro copy : https://excelfox.com/forum/showthrea...ll=1#post14573 )
    Last edited by DocAElstein; 07-12-2020 at 05:33 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
  •