Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Attribute VB_Name = "Module1"
  2. Function FindNextStringValue(s As Long) As Long
  3.     FindNextStringValue = s + 1
  4.     If IsEmpty(Cells(FindNextStringValue, "A")) Then
  5.         FindNextStringValue = -1
  6.     End If
  7. End Function
  8.  
  9.  
  10. Function FindNextMainDepartmentStringValue(s As Long) As Long
  11.     FindNextMainDepartmentStringValue = -1
  12.     Dim curr As Long
  13.     curr = s
  14.    
  15.     Do
  16.         curr = FindNextStringValue(curr)
  17.         If curr = -1 Then
  18.             Exit Function
  19.         End If
  20.     Loop While IsEmpty(Cells(curr, "C"))
  21.     FindNextMainDepartmentStringValue = curr
  22. End Function
  23.  
  24.  
  25. Sub CompareTwo(CurrLine As Long, NextLine As Long)
  26.     If StrComp(UCase(Cells(CurrLine, "A")), UCase(Cells(NextLine, "A"))) = 0 Then
  27.         If IsEmpty(Cells(CurrLine, "D")) Then
  28.             Cells(CurrLine, "D").Value = CStr(Cells(CurrLine, "C").Value)
  29.         End If
  30.        
  31.         If StrComp(Cells(CurrLine, "C").Value, Cells(CurrLine, "D").Value) = 0 Then
  32.             Cells(CurrLine, "D").Font.Color = vbRed
  33.         End If
  34.        
  35.         Cells(NextLine, "D").Value = CStr(Cells(CurrLine, "D").Value)
  36.     End If
  37. End Sub
  38.  
  39.  
  40. Sub GetDefaultCell(c As Range)
  41.    
  42.     c.Font.Color = vbBlack
  43. End Sub
  44.  
  45.  
  46. Sub Fill()
  47.     Dim CurrLine As Long
  48.     CurrLine = 2
  49.    
  50.     Dim NextLine As Long
  51.    
  52.     Do
  53.         NextLine = FindNextMainDepartmentStringValue(CurrLine)
  54.         If NextLine <> -1 Then
  55.             Call GetDefaultCell(Cells(CurrLine, "D"))
  56.             'Cells(CurrLine, "E").Value = NextLine
  57.            Call CompareTwo(CurrLine, NextLine)
  58.             CurrLine = NextLine
  59.         End If
  60.     Loop While NextLine <> -1
  61. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement