Forum Discussion
TarakK
Sep 26, 2020Copper Contributor
Seeking Recommendations for Excel Data Cleaner
Every month I get about 40 Excel files and need to clean the data (remove extraneous rows and columns, remove unnecessary headers, ensure all values are numbers not text, convert merged cells to regu...
NikolinoDE
Sep 27, 2020Platinum Contributor
Many roads lead to Rome, as well as many proposed solutions in Excel lead to a solution.
Here is a small VBA example to clean files / worksheets, etc. yourself, you just have to adapt to what you want to clean exactly.
Sub clean ()
Dim wksA As Worksheet
Dim rngB As Range
Dim lngLine As Long
Dim lngLastline As Long
Set wksA = ActiveWorkbook.Worksheets ("Sheet1") 'adjust !!
lngLlastZeil = wksA.Cells (wksA.Rows.Count, 2) .End (xlUp) .Row
wksA.AutoFilterMode = False
wksA.Range (wksA.Cells (4, 1), wksA.Cells (last line, 22)). Sort _
Key1: = wksA.Cells (4, 21), _
Order1: = xlDescending, _
Header: = xlNo, _
OrderCustom: = 1, _
MatchCase: = False, _
Orientation: = xlTopToBottom, _
DataOption1: = xlSortNormal
For lngZeile = lngLlastZeil To 5 Step -1
If Application.WorksheetFunction.CountIf (wksA.Range (wksA.Cells (3, 2), wksA.Cells (lngZeile, 2)), wksA.Cells (lngZeile, 2))> 1 Then
wksA.Rows (lngZeile) .Delete
End If
Next
'possibly. sort the names
last line = wksA.Cells (wksA.Rows.Count, 2) .End (xlUp) .Row
wksA.Range (wksA.Cells (4, 1), wksA.Cells (last line, 22)). Sort _
Key1: = wksA.Cells (4, 2), _
Order1: = xlAscending, _
Header: = xlNo, _
OrderCustom: = 1, _
MatchCase: = False, _
Orientation: = xlTopToBottom, _
DataOption1: = xlSortNormal
End Sub
'From German to English translate
Nikolino
I know I don't know anything (Socrates)