-
Notifications
You must be signed in to change notification settings - Fork 0
/
pruebas.vb
441 lines (283 loc) · 9.44 KB
/
pruebas.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
Sub trim()
For Each celda In Selection
celda.Value = WorksheetFunction.trim(celda.Value)
Next
End Sub
Sub comas()
Set aa = Range("W2", Range("W2").End(xlDown))
Set bb = Range("X2", Range("X2").End(xlDown))
Set cc = Range("Y2", Range("Y2").End(xlDown))
Set dd = Range("Z2", Range("Z2").End(xlDown))
Set ee = Range("AA2", Range("AA2").End(xlDown))
Union(aa, bb, cc, dd, ee).Select
With Selection
.Replace What:=",", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByColumns
End With
End Sub
Sub codcierr()
Dim cod_Cierr As String
Dim ultFila As Long
Dim cont As Long
Dim celda As Range
'COD_CIERR
ultFila = Range("A" & rows.Count).End(xlUp).Row
For cont = 2 To ultFila
cod_Cierr = Cells(cont, 13)
If cod_Cierr = "-" Then
Cells(cont, 13) = "SIN DATO"
End If
Next cont
End Sub
Sub homicidios()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = VBA.UCase(Rng.Value)
Next
With Selection
.Replace What:="á", Replacement:="a", LookAt:=xlPart, SearchOrder:=xlByColumns
.Replace What:="é", Replacement:="e", LookAt:=xlPart, SearchOrder:=xlByColumns
.Replace What:="í", Replacement:="i", LookAt:=xlPart, SearchOrder:=xlByColumns
.Replace What:="ó", Replacement:="o", LookAt:=xlPart, SearchOrder:=xlByColumns
.Replace What:="ú", Replacement:="u", LookAt:=xlPart, SearchOrder:=xlByColumns
.Replace What:="ü", Replacement:="u", LookAt:=xlPart, SearchOrder:=xlByColumns
End With
End Sub
Sub UCase()
'Upadateby20140701
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = VBA.UCase(Rng.Value)
Next
End Sub
Sub textoANumero()
Dim celda As Range
Range("A2", Range("A2").End(xlDown)).Select
For Each celda In Selection
celda.Value = CStr(celda)
Next celda
End Sub
Sub resize()
Dim LR As Long
Dim LC As Long
Worksheets("COORDENADAS").Select
LR = Cells(rows.Count, 1).End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
Cells(1, 1).resize(LR, LC).Select
'Dim rows As Long, numcolumns As Integer
'numrows = Selection.rows.Count
'numcolumns = Selection.Columns.Count
'Selection.resize(numrows + 10, numcolumns + 5).Select
End Sub
Option Explicit
Sub RecorrerCeldas()
Dim celda As Range
For Each celda In Selection
If Not VBA.IsNumeric(celda) Then
celda.Font.Bold = True
End If
Next celda
End Sub
Sub ValidarCelda()
Dim celda As Range
For Each celda In Range("A2:BK14")
If VBA.IsNumeric(celda) = True Then
celda.Interior.Color = VBA.vbGreen
End If
Next celda
For Each celda In Range("A2:BK14")
If Not VBA.IsNumeric(celda) Then
celda.Font.Bold = True
End If
Next celda
End Sub
Sub seleccionarColumna()
' Esta Macro solamente acepta datos contiguos, se detiene en celdas en blanco
'Range("AX2", Range("AX2").End(xlDown)).Select
' Esta Macro puede elegir los datos de una columna aun no siendo contiguos
'Range("AX2", Range("AX1048576").End(xlUp)).Select
' Esta Macro resalta toda el área de trabajo en uso
Selection.CurrentRegion.Select
End Sub
Sub experimentos()
Dim celda As Range
Selection.CurrentRegion.Select
With Selection
.Replace What:="" & Chr(10) & "", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByColumns
End With
For Each celda In Selection
celda.Value = LTrim(celda.Value)
celda.Value = RTrim(celda.Value)
celda.Value = WorksheetFunction.trim(celda.Value)
Next
End Sub
Sub cambiarSeleccion()
ActiveSheet.Range("A2", Range("A2").End(xlDown)).Select
Selection.resize(, 46).Select
End Sub
Sub Renumbering()
'https://es.extendoffice.com/documents/excel/2209-excel-auto-number-after-filter.html#:~:text=1%201.%20Mantenga%20pulsado%20el%20ALT%20%2B%20F11,o%20renumerar%20despu%C3%A9s%20del%20filtro%20...%20M%C3%A1s%20elementos
'Updateby Extendoffice
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.Columns(1).SpecialCells(xlCellTypeVisible)
xIndex = 1
For Each rng In WorkRng
rng.Value = xIndex
xIndex = xIndex + 1
Next
End Sub
Sub AñadirSeries()
'https://www.desafiandoexcel.com/macros-de-excel/numeros-seriales-o-secuenciales-en-excel-macro/#:~:text=La%20siguiente%20macro%20nos%20permite%20generar%20r%C3%A1pidamente%20una,debemos%20configurar%20el%20%C3%BAltimo%20valor%20para%20dicha%20serie.
Dim i As Integer
On Error GoTo Last
i = InputBox("Ingresar último valor", "Números seriales")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last: Exit Sub
End Sub
Sub NumeracionAutomatica()
Dim i As Integer
i = 1
Do While Not IsEmpty(Cells(i, 1))
Cells(i, 1).Value = i
i = i + 1
Loop
End Sub
Sub AutoGeneratedSerialNumber()
'https://www.exceldemy.com/auto-generate-serial-number-in-excel-vba/
For m = 2 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(m, "B").Value <> "" Then
Cells(m, "A").Value = m - 1
End If
Next m
End Sub
Sub cambiarSeleccion()
ActiveSheet.Range("A2", Range("A2").End(xlDown)).Select
Selection.resize(, 46).Select
End Sub
Sub Renumbering()
'https://es.extendoffice.com/documents/excel/2209-excel-auto-number-after-filter.html#:~:text=1%201.%20Mantenga%20pulsado%20el%20ALT%20%2B%20F11,o%20renumerar%20despu%C3%A9s%20del%20filtro%20...%20M%C3%A1s%20elementos
'Updateby Extendoffice
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.Columns(1).SpecialCells(xlCellTypeVisible)
xIndex = 1
For Each rng In WorkRng
rng.Value = xIndex
xIndex = xIndex + 1
Next
End Sub
Sub AñadirSeries()
'https://www.desafiandoexcel.com/macros-de-excel/numeros-seriales-o-secuenciales-en-excel-macro/#:~:text=La%20siguiente%20macro%20nos%20permite%20generar%20r%C3%A1pidamente%20una,debemos%20configurar%20el%20%C3%BAltimo%20valor%20para%20dicha%20serie.
Dim i As Integer
On Error GoTo Last
i = InputBox("Ingresar último valor", "Números seriales")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last: Exit Sub
End Sub
Sub NumeracionAutomatica()
Dim i As Integer
i = 1
Do While Not IsEmpty(Cells(i, 1))
Cells(i, 1).Value = i
i = i + 1
Loop
End Sub
Sub AutoGeneratedSerialNumber()
'https://www.exceldemy.com/auto-generate-serial-number-in-excel-vba/
For m = 2 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(m, "B").Value <> "" Then
Cells(m, "A").Value = m - 1
End If
Next m
End Sub
Sub recorte()
Range("S:S").Value = trim(Range("S:S"))
End Sub
'https://exceltotal.com/como-quitar-acentos-en-excel/
Function QUITARACENTOS(cadena As String) As String
Dim posicion As Long
Const conAcento As String = "áéíóúÁÉÍÓÚ"
Const sinAcento As String = "aeiouAEIOU"
For i = 1 To Len(conAcento)
cadena = Replace(cadena, Mid(conAcento, i, 1), Mid(sinAcento, i, 1))
Next i
QUITARACENTOS = cadena
End Function
End Sub
Sub textoANumero()
Dim celda As Range
Range("A2", Range("A2").End(xlDown)).Select
For Each celda In Selection
celda.Value = CStr(celda)
Next celda
End Sub
Sub resize()
Dim LR As Long
Dim LC As Long
Worksheets("COORDENADAS").Select
LR = Cells(Rows.Count, 1).End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
Cells(1, 1).resize(LR, LC).Select
'Dim rows As Long, numcolumns As Integer
'numrows = Selection.rows.Count
'numcolumns = Selection.Columns.Count
'Selection.resize(numrows + 10, numcolumns + 5).Select
End Sub
Sub RecorrerCeldas()
Dim celda As Range
For Each celda In Selection
If Not VBA.IsNumeric(celda) Then
celda.Font.Bold = True
End If
Next celda
End Sub
Sub ValidarCelda()
Dim celda As Range
For Each celda In Range("A2:BK14")
If VBA.IsNumeric(celda) = True Then
celda.Interior.Color = VBA.vbGreen
End If
Next celda
For Each celda In Range("A2:BK14")
If Not VBA.IsNumeric(celda) Then
celda.Font.Bold = True
End If
Next celda
End Sub
Sub experimentos()
Dim celda As Range
Selection.CurrentRegion.Select
With Selection
.Replace What:="" & Chr(10) & "", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByColumns
End With
For Each celda In Selection
celda.Value = LTrim(celda.Value)
celda.Value = RTrim(celda.Value)
celda.Value = WorksheetFunction.trim(celda.Value)
Next
End Sub