Advertisement
AlanElston

Phillip Simplified

Feb 3rd, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Public Sub Worksheet_SelectionChange(ByVal Target As Range)
  3.     If IsArray(Target.Value) Then Exit Sub
  4. Rem 1 main worksheet data range info
  5. Dim CntItms As Long: Let CntItms = Me.Range("B" & Rows.Count & "").End(xlUp).Row
  6.     If Application.Intersect(Target, Me.Range("A2:A" & CntItms & "")) Is Nothing Then Exit Sub
  7.     If Worksheets("DataSaladinValagationLists").Range("A" & Target.Row & "").Value <> "" Then Exit Sub
  8. Dim CntClms As Long: Let CntClms = Me.Cells.Item(1, Columns.Count).End(xlToLeft).Column
  9. Rem 2 make drop down list for this row
  10.  
  11.  Let Application.EnableEvents = False
  12.  Me.Range("C" & Target.Row & "", Me.Cells.Item(Target.Row, CntClms)).SpecialCells(xlCellTypeConstants).Copy
  13.  Let Application.EnableEvents = True
  14. Dim Dtaobj As Object
  15.  Set Dtaobj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  16.  Dtaobj.GetFromClipboard: Dim strClip As String: Let strClip = Dtaobj.GetText()
  17.  Let strClip = Left(strClip, Len(strClip) - 2)
  18. Application.CutCopyMode = False
  19. Dim strSptInDrpPlop() As String: Let strSptInDrpPlop() = Split(strClip, vbTab, -1, vbBinaryCompare)
  20. Dim UnEeks As String
  21. Dim Cnt As Long
  22.     For Cnt = 0 To UBound(strSptInDrpPlop())
  23.      If InStr(1, UnEeks, Trim(strSptInDrpPlop(Cnt)), vbBinaryCompare) = 0 And Not Trim(strSptInDrpPlop(Cnt)) = "" And Not strSptInDrpPlop(Cnt) = vbTab Then
  24.       Let UnEeks = UnEeks & Trim(strSptInDrpPlop(Cnt)) & " "
  25.      Else
  26.      End If
  27.     Next Cnt
  28.  
  29.  Let UnEeks = Left(UnEeks, Len(UnEeks) - 1)
  30.  
  31.  Let strSptInDrpPlop() = Split(UnEeks, " ", -1, vbBinaryCompare)
  32.  
  33. Dim Eye As Long, Jay As Long
  34.     For Eye = 0 To UBound(strSptInDrpPlop()) - 1
  35.        For Jay = Eye + 1 To UBound(strSptInDrpPlop())
  36.            If IsNumeric(strSptInDrpPlop(Eye)) And IsNumeric(strSptInDrpPlop(Jay)) Then
  37.                 If CLng(strSptInDrpPlop(Eye)) > CLng(strSptInDrpPlop(Jay)) Then
  38.                 Dim Temp As String: Let Temp = strSptInDrpPlop(Jay): Let strSptInDrpPlop(Jay) = strSptInDrpPlop(Eye): Let strSptInDrpPlop(Eye) = Temp
  39.                 Else
  40.                 End If
  41.            Else
  42.                 If strSptInDrpPlop(Eye) > strSptInDrpPlop(Jay) Then
  43.                  Let Temp = strSptInDrpPlop(Jay): Let strSptInDrpPlop(Jay) = strSptInDrpPlop(Eye): Let strSptInDrpPlop(Eye) = Temp
  44.                 Else
  45.                 End If
  46.            End If
  47.        Next Jay
  48.     Next Eye
  49.  
  50.     With Worksheets("DataSaladinValagationLists")
  51.      Let .Range("A" & Target.Row & "").Value = "-"
  52.      Let .Cells.Item(Target.Row, 2).Resize(1, UBound(strSptInDrpPlop()) + 1).Value = strSptInDrpPlop()
  53.      Let .Cells.Item(Target.Row, UBound(strSptInDrpPlop()) + 3).Value = "Blank"
  54.     End With
  55.  
  56. Target.Validation.Delete
  57. Target.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=DataSaladinValagationLists!A" & Target.Row & ":" & CLDoWhile(UBound(strSptInDrpPlop()) + 3) & "" & Target.Row & ""
  58. End Sub
  59. Function CLDoWhile(ByVal lclm As Long) As String
  60. Dim rest As Long
  61.     Do
  62.      
  63.     Let CLDoWhile = Chr(65 + (((lclm - 1) Mod 26))) & CLDoWhile
  64.     Let lclm = (lclm - (1)) \ 26
  65.    
  66.     Loop While lclm > 0
  67. End Function
  68. Public Sub Worksheet_Change(ByVal Target As Range)
  69.     If IsArray(Target.Value) Then Exit Sub
  70. Rem 1 main worksheet data range info
  71. Dim CntItms As Long: Let CntItms = Me.Range("B" & Rows.Count & "").End(xlUp).Row
  72.     If Application.Intersect(Target, Me.Range("A2:A" & CntItms & "")) Is Nothing Then Exit Sub
  73. Dim CntClms As Long: Let CntClms = Me.Cells.Item(1, Columns.Count).End(xlToLeft).Column
  74.     If Target.Value = "Blank" Then Let Application.EnableEvents = False: Let Target.Value = "": Let Application.EnableEvents = True
  75. Rem 2 test data range reset
  76.     If Target.Value = "-" Then
  77.      Let Application.EnableEvents = False
  78.      Let Me.Range("C1", Me.Cells.Item(CntItms, Worksheets("Sheet1 (2)").Cells.Item(1, Columns.Count).End(xlToLeft).Column)).Value = Worksheets("Sheet1 (2)").Range("C1", Worksheets("Sheet1 (2)").Cells.Item(CntItms, Worksheets("Sheet1 (2)").Cells.Item(1, Columns.Count).End(xlToLeft).Column)).Value
  79.      Let Application.EnableEvents = True
  80. Rem 3 Get indices( column numbers) for required columns, and all row indicies
  81.    
  82.     Else
  83.     Dim arrLine() As Variant: Let arrLine() = Me.Range(Me.Cells.Item(Target.Row, 1), Me.Cells.Item(Target.Row, CntClms)).Value
  84.     Dim Cnt As Long
  85.     Dim strClms As String: Let strClms = "1 2 "
  86.         For Cnt = 3 To CntClms
  87.             If CStr(arrLine(1, Cnt)) = CStr(Target.Value) Then
  88.              Let strClms = strClms & Cnt & " "
  89.             Else
  90.             End If
  91.         Next Cnt
  92.      Let strClms = Left(strClms, Len(strClms) - 1)
  93.     Dim clmsSpt() As String: Let clmsSpt() = Split(strClms, " ", -1, vbBinaryCompare)
  94.     Dim Clms() As String: ReDim Clms(1 To UBound(clmsSpt()) + 1)
  95.         For Cnt = 0 To UBound(clmsSpt())
  96.          Let Clms(Cnt + 1) = clmsSpt(Cnt)
  97.         Next Cnt
  98.    
  99.     Dim Rws() As Variant: Let Rws() = Evaluate("=Row(1:" & CntItms & ")")
  100. Rem 4 Output filtered columns
  101.      Dim arrOut() As Variant: Let arrOut() = Application.Index(Cells, Rws(), Clms())
  102.      Let Application.EnableEvents = False
  103.      Me.Cells.ClearContents
  104.      Let Range("A1").Resize(UBound(arrOut(), 1), UBound(arrOut(), 2)).Value = arrOut()
  105.      Let Application.EnableEvents = True
  106.     End If
  107. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement