Melanie1987
New Member
- Joined
- Jul 2, 2018
- Messages
- 5
Hello,
I'm trying to make this code work for all my sheets.
But after trying for several hours I give up.
The problem seems to be that the code doesn't loop through the sheets.
I'm hoping somebody can help me.
I'm trying to make this code work for all my sheets.
But after trying for several hours I give up.
The problem seems to be that the code doesn't loop through the sheets.
Code:
Sub NaDataInvoegen()
Application.ScreenUpdating = False
Call VerwijderMonstervoorbewerking1
Call VerwijderOpwerkingMineralen
Call TekstNaarGetal
Call ReplaceTitle
Call CreateSheet
Call CellenUitlijnenenFilter
Application.ScreenUpdating = True
End Sub
Sub VerwijderMonstervoorbewerking1()
Dim i As Long
lst = Range("G" & Rows.Count).End(xlUp).Row
For i = lst To 2 Step -1
If Range("G" & i).Value Like "*Monstervoorbewerking*" Then
Range("G" & i).EntireRow.Delete
End If
Next i
End Sub
Sub VerwijderOpwerkingMineralen()
Dim i As Long
lst = Range("G" & Rows.Count).End(xlUp).Row
For i = lst To 2 Step -1
If Range("G" & i).Value Like "*Opwerking mineralen*" Then
Range("G" & i).EntireRow.Delete
End If
Next i
End Sub
Sub TekstNaarGetal()
Columns("H:H").Select
Selection.TextToColumns Destination:=Range("H1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), DecimalSeparator:=".", ThousandsSeparator:=" ", _
TrailingMinusNumbers:=True
ActiveCell.Select
End Sub
Sub ReplaceTitle()
Columns("K").Replace What:="Geëvaporeerde / geconcentreerde melk", _
Replacement:="Geëvap_geconcentreerde melk", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End Sub
Sub CreateSheet()
Dim bottomA As Long
bottomK = Sheets("data").Range("K" & Rows.Count).End(xlUp).Row
Dim Rng As Range
Dim WS As Worksheet
Dim rngUniques As Range
Sheets("data").Range("K1:K" & bottomK).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("K1:K" & bottomK), Unique:=True
Set rngUniques = Sheets("data").Range("K2:K" & bottomK).SpecialCells(xlCellTypeVisible)
If Sheets("data").AutoFilterMode = True Then Sheets("data").AutoFilterMode = False
For Each Rng In rngUniques
Set WS = Nothing
On Error Resume Next
Set WS = Worksheets(Rng.Value)
On Error GoTo 0
If WS Is Nothing Then
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = Rng.Value
Sheets("data").Rows(1).Copy Cells(1, 1)
End If
Next Rng
For Each Rng In rngUniques
Sheets(Rng.Value).UsedRange.Offset(1, 0).ClearContents
Sheets("data").Range("K1:K" & bottomK).AutoFilter Field:=1, Criteria1:=Rng
Sheets("data").Range("K2:K" & bottomK).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(Rng.Value).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
If Sheets("data").AutoFilterMode = True Then Sheets("data").AutoFilterMode = False
Next Rng
Sheets("data").Select
End Sub
Sub CellenUitlijnenenFilter()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Cells.Select
Cells.EntireColumn.AutoFit
Rows("1:1").Select
Selection.AutoFilter
Next WS
Sheets("data").Select
End Sub
I'm hoping somebody can help me.