Prikazi cijelu temu 14.01.2019 21:49
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Lokacija:zagreb


Predmet:Re: Kako da obrisem redove sa markiranim celijama
PreuzmiIzvorni kôd (Text):
  1. Sub duplikati()
  2.     If obojiDuplikate = True Then
  3.         If obrisiDuplikate = False Then
  4.             MsgBox "GRESKA! u brisanju duplikata"
  5.             Stop
  6.         End If
  7.     Else
  8.         MsgBox "GRESKA! u bojanju duplikata"
  9.         Stop
  10.     End If
  11. End Sub
  12.  
  13. Function obojiDuplikate() As Boolean
  14.     obojiDuplikate = False
  15.    
  16.     Dim LLoop As Long
  17.     Dim LTestLoop As Long
  18.     Dim LClearRange As String
  19.     Dim Lrows As Long
  20.     Dim Lcol As Long
  21.     Dim LRange As String
  22.  
  23.     'A kolona, vrijednosti
  24.     Dim LChangedValue As String
  25.     Dim LTestValue As String
  26.  
  27.     'B kolona vrijednosti
  28.     Dim LChangedValueB As String
  29.     Dim LTestValueB As String
  30.      
  31.     With Application
  32.         .Calculation = xlCalculationManual
  33.         .ScreenUpdating = False
  34.     End With
  35.  
  36.     'Lrows=zadnjiRed
  37.     With ActiveSheet
  38.         Lrows = .Cells(Rows.count, "A").End(xlUp).Row
  39.         Lcol = .Cells(1, Columns.count).End(xlToLeft).Column
  40.     End With
  41.  
  42.     LLoop = 2
  43.  
  44.     'obrisi boje ispune
  45.     LClearRange = "A2:B" & Lrows
  46.     Range(LClearRange).Interior.ColorIndex = xlNone
  47.  
  48.     'provjeri sve redove
  49.     While LLoop <= Lrows
  50.         LChangedValue = "A" & CStr(LLoop)
  51.         LChangedValueB = "B" & CStr(LLoop)
  52.         If Len(Range(LChangedValue).Value) > 0 Then
  53.  
  54.          'Nadi jedinstvenu vrijednost
  55.          LTestLoop = 2
  56.          While LTestLoop <= Lrows
  57.             If LLoop <> LTestLoop Then
  58.                LTestValue = "A" & CStr(LTestLoop)
  59.                LTestValueB = "B" & CStr(LTestLoop)
  60.                'vrijednost je duplikat u drugoj celiji
  61.                If (Range(LChangedValue).Value = Range(LTestValue).Value) And (Range(LChangedValueB).Value = Range(LTestValueB).Value) Then
  62.                   'postavi crvenu boju pozadine u A stupcu
  63.                   Range(LChangedValue).Interior.ColorIndex = 3
  64.                   Range(LTestValue).Interior.ColorIndex = 3
  65.  
  66.                   'postavi crvenu boju pozadine u B stupcu
  67.                   'ovo netreba
  68.                   Range(LChangedValueB).Interior.ColorIndex = 3
  69.                   Range(LTestValueB).Interior.ColorIndex = 3
  70.                End If
  71.             End If
  72.             LTestLoop = LTestLoop + 1
  73.             Wend
  74.         End If
  75.         LLoop = LLoop + 1
  76.     Wend
  77.     obojiDuplikate = True
  78.  
  79.     With Application
  80.         .Calculation = xlCalculationAutomatic
  81.         .ScreenUpdating = True
  82.     End With
  83.  
  84. End Function
  85.  
  86. Function obrisiDuplikate() As Boolean
  87.     obrisiDuplikate = False
  88.    
  89.     Dim rCell As Range
  90.     Dim rRange As Range
  91.     Dim lCount As Long
  92.      
  93.  
  94.     With Application
  95.         .Calculation = xlCalculationManual
  96.         .ScreenUpdating = False
  97.     End With
  98.  
  99.     Set rRange = Range("A1", Range("A" & Rows.count).End(xlUp))
  100.     lCount = rRange.Rows.count
  101.      
  102.     For lCount = lCount To 1 Step -1
  103.         With rRange.Cells(lCount, 1)
  104.             If WorksheetFunction.CountIf(rRange, .Value) > 1 Then
  105.                 .EntireRow.Delete
  106.             End If
  107.         End With
  108.     Next lCount
  109.     obrisiDuplikate = True
  110.  
  111.     With Application
  112.         .Calculation = xlCalculationAutomatic
  113.         .ScreenUpdating = True
  114.     End With
  115.  
  116. End Function

zivot je moja domovina.
Ovaj post je ureden 3 puta. Posljednja izmjena 15.01.2019 11:26 od strane Avko.