-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacrocode.vb
207 lines (163 loc) · 6.14 KB
/
macrocode.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Sub ZeilenLoeschen()
ActiveSheet.Rows("1:5").Delete
End Sub
Public Sub spalten_bereinigen()
With Worksheets(1).Range("1:1")
ActiveSheet.Rows(1).Find(what:="Search Engines", Lookat:=xlWhole).EntireColumn.Delete
ActiveSheet.Rows(1).Find(what:="Gruppen", Lookat:=xlWhole).EntireColumn.Delete
ActiveSheet.Rows(1).Find(what:="Diff", Lookat:=xlWhole).EntireColumn.Delete
ActiveSheet.Rows(1).Find(what:="Date", Lookat:=xlWhole).EntireColumn.Delete
End With
'ActiveSheet.Columns().Delete
End Sub
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
' Namen der Tabellen anpassen
On Error Resume Next
ActiveWorkbook.Worksheets("All schedules").Delete
' ...
On Error GoTo 0
Application.DisplayAlerts = True
End Sub
Option Explicit
Sub ZeileLoeschen1()
Dim LastRow As Long, LastCol As Integer
Dim lRow As Long, lCol As Integer
Dim i As Long
'Maximale Werte feststellen
With ActiveSheet
lCol = .UsedRange.Columns.Count
lRow = .UsedRange.Rows.Count
For i = 1 To lCol
LastRow = Application.WorksheetFunction.Max(.Cells(Rows.Count, i).End(xlUp).Row, LastRow)
Next i
For i = 1 To lRow
LastCol = Application.WorksheetFunction.Max(.Cells(i, Columns.Count).End(xlToLeft).Column, LastCol)
Next i
End With
'letzte Zeile mit Daten komplett löschen
Rows(LastRow).EntireRow.Delete
End Sub
Option Explicit
Sub ZeileLoeschen2()
Dim LastRow As Long, LastCol As Integer
Dim lRow As Long, lCol As Integer
Dim i As Long
'Maximale Werte feststellen
With ActiveSheet
lCol = .UsedRange.Columns.Count
lRow = .UsedRange.Rows.Count
For i = 1 To lCol
LastRow = Application.WorksheetFunction.Max(.Cells(Rows.Count, i).End(xlUp).Row, LastRow)
Next i
For i = 1 To lRow
LastCol = Application.WorksheetFunction.Max(.Cells(i, Columns.Count).End(xlToLeft).Column, LastCol)
Next i
End With
'letzte Zeile mit Daten komplett löschen
Rows(LastRow).EntireRow.Delete
End Sub
Option Explicit
Sub ZeileLoeschen3()
Dim LastRow As Long, LastCol As Integer
Dim lRow As Long, lCol As Integer
Dim i As Long
'Maximale Werte feststellen
With ActiveSheet
lCol = .UsedRange.Columns.Count
lRow = .UsedRange.Rows.Count
For i = 1 To lCol
LastRow = Application.WorksheetFunction.Max(.Cells(Rows.Count, i).End(xlUp).Row, LastRow)
Next i
For i = 1 To lRow
LastCol = Application.WorksheetFunction.Max(.Cells(i, Columns.Count).End(xlToLeft).Column, LastCol)
Next i
End With
'letzte Zeile mit Daten komplett löschen
Rows(LastRow).EntireRow.Delete
End Sub
*********************************************
Public Sub DateiWaehlen()
Dim vntFile As Variant
Dim pfad As String
Dim objWorkbook As Workbook
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "!!! DATEI WÄHLEN !!!"
.AllowMultiSelect = True
.InitialFileName = pfad
With .Filters
If .Count > 0 Then Call .Clear
.Add "Excel 2010", "*.xlsx"
.Add "Excel 2003", "*.xls"
.Add "Alle", "*.*"
End With
If .Show = -1 Then
For Each vntFile In .SelectedItems
Set objWorkbook = Workbooks.Open(vntFile)
ActiveSheet.Rows("1:5").Delete 'Erste 5 Zeilen löschen
With Worksheets(1).Range("1:1") 'Bereich auswählen
ActiveSheet.Rows(1).Find(what:="Search Engines", Lookat:=xlWhole).EntireColumn.Delete 'Kolumne "Search Engines" löschen
ActiveSheet.Rows(1).Find(what:="Diff", Lookat:=xlWhole).EntireColumn.Delete 'Kolumne "Diff" löschen
ActiveSheet.Rows(1).Find(what:="Date", Lookat:=xlWhole).EntireColumn.Delete 'Kolumne "Date" löschen
End With 'Unnötige Kolumnen gelöscht
Application.DisplayAlerts = False 'Löschung des unnötigen Tabs
On Error Resume Next
ActiveWorkbook.Worksheets("All schedules").Delete
On Error GoTo 0
Application.DisplayAlerts = True ' Tab gelöscht
' letzte Zeile löschen
Dim LastRow1 As Long, LastCol1 As Integer
Dim lRow1 As Long, lCol1 As Integer
Dim i As Long
With ActiveSheet
lCol1 = .UsedRange.Columns.Count
lRow1 = .UsedRange.Rows.Count
For i = 1 To lCol1
LastRow1 = Application.WorksheetFunction.Max(.Cells(Rows.Count, i).End(xlUp).Row, LastRow1)
Next i
For i = 1 To lRow1
LastCol1 = Application.WorksheetFunction.Max(.Cells(i, Columns.Count).End(xlToLeft).Column, LastCol1)
Next i
End With
Rows(LastRow1).EntireRow.Delete
' letzte Zeile gelöscht
' letzte Zeile löschen
Dim LastRow2 As Long, LastCol2 As Integer
Dim lRow2 As Long, lCol2 As Integer
Dim a As Long
With ActiveSheet
lCol2 = .UsedRange.Columns.Count
lRow2 = .UsedRange.Rows.Count
For a = 1 To lCol2
LastRow2 = Application.WorksheetFunction.Max(.Cells(Rows.Count, a).End(xlUp).Row, LastRow2)
Next a
For a = 1 To lRow2
LastCol2 = Application.WorksheetFunction.Max(.Cells(a, Columns.Count).End(xlToLeft).Column, LastCol2)
Next a
End With
Rows(LastRow2).EntireRow.Delete
' letzte Zeile gelöscht
' letzte Zeile löschen
Dim LastRow3 As Long, LastCol3 As Integer
Dim lRow3 As Long, lCol3 As Integer
Dim o As Long
With ActiveSheet
lCol3 = .UsedRange.Columns.Count
lRow3 = .UsedRange.Rows.Count
For o = 1 To lCol3
LastRow3 = Application.WorksheetFunction.Max(.Cells(Rows.Count, o).End(xlUp).Row, LastRow3)
Next o
For o = 1 To lRow3
LastCol3 = Application.WorksheetFunction.Max(.Cells(o, Columns.Count).End(xlToLeft).Column, LastCol3)
Next o
End With
Rows(LastRow3).EntireRow.Delete
' letzte Zeile gelöscht
Call objWorkbook.Save
Set objWorkbook = Nothing
Next
Else
MsgBox "!!! KEINE DATEI AUSGEWÄHLT !!!", vbExclamation, "!!! WARNUNG !!!"
End If
End With
End Sub