Entradas

Macro para ordenar automáticamente de manera ascendente o descendente un tabla en base a un determinada columna

Código Private Sub Worksheet_Change(ByVal Target As Range) Dim w As Worksheet, t As ListObject, c As ListColumn Set w = ThisWorkbook.Worksheets("") Set t = w.ListObjects("") Set c = t.ListColumns("") If Not Intersect(Target, c.DataBodyRange) Is Nothing Then With t.Sort .SortFields.Clear .SortFields.Add2 Key:=c.DataBodyRange, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With t.ShowAutoFilter = False End If End Sub

Función para hallar el signo y elemento zodiacal a partir de una fecha en Excel

Imagen
Código Function IB·SignoZodiacal(FechaNacimiento As Date, Optional Elemento As Boolean = False) As String Dim D As Integer, H As Integer D = Day(FechaNacimiento) H = Month(FechaNacimiento) Select Case H Case 1 If D <= 19 Then If Elemento Then IB·SignoZodiacal = "Tierra" Else IB·SignoZodiacal = "Capricornio" End If Else If Elemento Then IB·SignoZodiacal = "Aire" Else IB·SignoZodiacal = "Acuario" End If End If Case 2 If D <= 18 Then If Elemento Then IB·SignoZodiacal = "Aire" Else IB·SignoZodiacal = "Acuario" End If Else If Elemento Then IB·SignoZodiacal = "Agua" Else IB·SignoZodiacal = "Piscis" End If End If Case 3 If D <= 20 Then If Elemento Then IB·SignoZodiacal = "Agua" Else IB·SignoZodiacal = "Piscis" End If Else If Elemento Then IB·SignoZodiacal = "Fuego" Else IB·SignoZodiacal = "Aries" End If End If Case 4 If D <= 19 Then If Elemento Then IB·SignoZodia...

UDF para interpolación y extrapolación lineal

Imagen
Código Function IB·InterExtrapolaciónLineal(Rango_X As Range, Rango_Y As Range, X As Double) As Variant Dim i As Long, n As Long, x1 As Double, x2 As Double, y1 As Double, y2 As Double n = Rango_X.Rows.Count For i = 1 To n - 1 If X >= Rango_X.Cells(i, 1).Value And X <= Rango_X.Cells(i + 1, 1).Value Then x1 = Rango_X.Cells(i, 1).Value x2 = Rango_X.Cells(i + 1, 1).Value y1 = Rango_Y.Cells(i, 1).Value y2 = Rango_Y.Cells(i + 1, 1).Value IB·InterExtrapolaciónLineal = y1 + (y2 - y1) * (X - x1) / (x2 - x1) Exit Function End If Next i If X < Rango_X.Cells(1, 1).Value Then x1 = Rango_X.Cells(1, 1).Value x2 = Rango_X.Cells(2, 1).Value y1 = Rango_Y.Cells(1, 1).Value y2 = Rango_Y.Cells(2, 1).Value IB·InterExtrapolaciónLineal = y1 + (y2 - y1) * (X - x1) / (x2 - x1) ElseIf X > Rango_X.Cells(n, 1).Value Then x1 = Rango_X.Cells(n - 1, 1).Value x2 = Rango_X.Cells(n, 1).Value y1 = Rango_Y.Cells(n - 1, 1).Value y2 = Rango_Y.Cells(n, 1).Value IB·InterExtrapolaciónLineal = y1 + (y2 - y1) * (X -...

Macro para obtener las fechas de un determinado mes y año en Excel

Código Private Sub Worksheet_Change(ByVal Target As Range) Dim FI As Date, FF As Date, RD As Range, F As Date, MES_AÑO_paraLISTA As Range, LISTAaPARTIRde As Range Set MES_AÑO_paraLISTA = Me.Range("") Set LISTAaPARTIRde = Me.Range("") If Not Intersect(Target, MES_AÑO_paraLISTA) Is Nothing Then Me.Range(LISTAaPARTIRde, Me.Cells(Me.Rows.Count, LISTAaPARTIRde.Column)).ClearContents If Trim(MES_AÑO_paraLISTA.Value) <> "" Then On Error Resume Next FI = DateValue(MES_AÑO_paraLISTA.Value & " 1") On Error GoTo 0 If FI <> 0 Then FF = DateSerial(Year(FI), Month(FI) + 1, 0) Set RD = LISTAaPARTIRde F = FI Do While F <= FF RD.Value = F Set RD = RD.Offset(1, 0) F = F + 1 Loop End If End If End If End Sub

Macro para dejar visible solo determinadas columnas

Código Sub MostrarColumnasEspecificas() Dim C As Variant, COcultar As Variant, CMostrar As Variant CMostrar = Array() COcultar = Array() For Each C In COcultar Columns(C).EntireColumn.Hidden = True Next C For Each C In CMostrar Columns(C).EntireColumn.Hidden = False Next C End Sub

Macro para aplicar Formato Negrita, Cursiva, Subrayado, Subrayado Doble a determinadas palabras en una concatenación en Excel

Código Sub IB·AplicarFormato() Dim R As Range, B As Range, C As Range, E As Variant Dim t As String, j As Range, o As String, x As Range, g As Variant, m As Variant On Error Resume Next Set R = Application.InputBox("Seleccione el rango donde se dará formato a las palabras:", "INGENIERÍA & BURÓTICA", , Type:=8) On Error GoTo 0 If R Is Nothing Then Exit Sub On Error Resume Next Set B = Application.InputBox("Seleccione el rango con las palabras a las que se dará formato:", "INGENIERÍA & BURÓTICA", Type:=8) On Error GoTo 0 If B Is Nothing Then Exit Sub E = Split(Replace(Trim(UCase(InputBox("Ingrese los códigos de formato separados por comas (N para negrita, K para cursiva, S para subrayado, D para subrayado doble):", "INGENIERÍA & BURÓTICA"))), " ", ""), ",") g = Array("N", "K", "S", "D") For Each m In E If Not IsError(Application.Match(m, g, 0)) The...

Macro para que una celda tome el valor de la celda activa de un determinado rango

Código: Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim RNG As Range    Set RNG = Range("C4:C10") If Not Intersect(Target, RNG) Is Nothing Then Range("F3").Value = Target.Value End If End Sub

Macro para separar texto de una celda con saltos de línea

Código: Sub IB·SepararSaltosDeLinea() Dim S As Range, D As Range, P As Variant, i As Long, j As Long, x As Long, F As String On Error Resume Next Set S = Application.InputBox("Rango que se desea separar", "INGENIERÍA & BURÓTICA", Type:=8) On Error GoTo 0 If S Is Nothing Then Exit Sub On Error Resume Next Set D = Application.InputBox("Celda a partir de la cual se enlistará:", "INGENIERÍA & BURÓTICA", Type:=8) On Error GoTo 0 If D Is Nothing Then Exit Sub F = UCase(InputBox("¿Enlistar horizontalmente (H) o verticalmente (V)?", "INGENIERÍA & BURÓTICA")) If F <> "H" And F <> "V" Then MsgBox "Opción inválida. Solo se permite H, h, V o v." Exit Sub End If x = 0 For Each cell In S P = Split(cell.Value, Chr(10)) For i = LBound(P) To UBound(P) If F = "H" Then D.Offset(x, i).Value = P(i) Else D.Offset(x + i, 0).Value = P(i) End If Next i x = x + IIf(F = "H", 1, UB...

Función para invertir el orden de números, letras o combinación de ambos

Código: Function IB·InvertirOrdenNL(Valor As String) As String     Dim C As Integer, i As Integer, A As String     C = Len(Valor)     For i = C To 1 Step -1         A = A & Mid(Valor, i, 1)     Next i     IB·InvertirOrdenNL = A End Function

Macro para eliminar fácilmente saltos de línea y espacios en blanco excesivos en Microsoft Power Point

Código: Sub EliminarEspaciosSaltosDeLinea() Dim F As Shape, C As textRange, T As String If Not ActiveWindow.Selection.Type = ppSelectionShapes Then MsgBox "Selecciona un cuadro de texto.", vbInformation Exit Sub End If Set F = ActiveWindow.Selection.ShapeRange(1) If Not F.HasTextFrame Then MsgBox "Selecciona un cuadro de texto.", vbInformation Exit Sub End If Set C = F.TextFrame.textRange C.Text = Replace(C.Text, Chr(13), " ") T = "" For I = 1 To Len(C.Text) If Not Mid(C.Text, I, 1) = " " Then T = T & Mid(C.Text, I, 1) ElseIf Not Mid(C.Text, I + 1, 1) = " " Then T = T & Mid(C.Text, I, 1) End If Next I C.Text = T C.ParagraphFormat.Alignment = ppAlignJustify End Sub

Macro para eliminar todas las imágenes de un documento word

Código: Sub EliminarImagenes()     Dim i As Long     For i = ActiveDocument.InlineShapes.Count To 1 Step -1         ActiveDocument.InlineShapes(i).Delete     Next i     For i = ActiveDocument.Shapes.Count To 1 Step -1         ActiveDocument.Shapes(i).Delete     Next i End Sub

Macro para eliminar fácilmente saltos de línea y espacios en blanco excesivos en Microsoft Word

Código: Sub EliminarEspaciosSaltosDeLinea()     Dim R As Range, C As Variant     Set R = Selection.Range     C = Array("^p", "^w")     For Each Char In C         With R.Find             .ClearFormatting             .Replacement.ClearFormatting             .Text = Char             .Replacement.Text = " "             .Forward = True             .Wrap = wdFindStop             .Format = False             .MatchCase = False             .MatchWholeWord = False             .MatchWildcards = False             .MatchSoundsLike = False             .MatchAllWordForms = False   ...

Macro para realizar fácilmente reemplazos múltiples de texto o números

  Código: Sub IBReemplazosMúltiples() Dim R As Range, B As Range, S As Range, C As Range, x As Range, y As Range On Error Resume Next Set R = Application.InputBox("Selecciona el rango donde se realizará el reemplazo de palabras:", Type:=8) On Error GoTo 0 If R Is Nothing Then Exit Sub On Error Resume Next Set B = Application.InputBox("Buscar:", Type:=8) On Error GoTo 0 If B Is Nothing Then Exit Sub On Error Resume Next Set S = Application.InputBox("Reemplazar con:", Type:=8) On Error GoTo 0 If S Is Nothing Then Exit Sub If Not (B.Cells.Count = S.Cells.Count) Then MsgBox "Los rangos de Buscar y Reemplazar con no tienen el mismo tamaño. Asegúrate de que ambos rangos tengan la misma cantidad de celdas." Exit Sub End If Application.ScreenUpdating = False For Each C In R If C.HasFormula Then For Each x In B Set y = S.Cells(x.Row - B.Cells(1).Row + 1) C.Formula = Replace(C.Formula, x.Value, y.Value, , , vbTextCompare) Next x Else For Each x In B Set y ...

Macro para extraer comentarios de una columna en Excel

Código: Sub IB·ExtraerComentarios() Dim R As Range, C As Range, I As Range, B As Comment On Error Resume Next Set R = Application.InputBox("Selecciona el rango del cual se extraerán los comentarios:", "INGENIERÍA & BURÓTICA", Type:=8) On Error GoTo 0 If R Is Nothing Then Exit Sub On Error Resume Next Set C = Application.InputBox("Selecciona la celda a partir de la cual se pegarán los comentarios:", "INGENIERÍA & BURÓTICA", , Type:=8) On Error GoTo 0 If C Is Nothing Then Exit Sub For Each I In R If Not I.Comment Is Nothing Then Set B = I.Comment C.Value = B.Text End If Set C = C.Offset(1) Next I MsgBox "Los comentarios se han extraído correctamente.", , "INGENIERÍA & BURÓTICA" End Sub

Función: IB·BuscarFC: Búsquedas por intersección de FILA y COLUMNA. Versión simplificada de Índice y Coincidir

Código: Function IB·BuscarFC(Rango_Busqueda As Range, Valor_Fila As Variant, Rango_Fila As Range, Valor_Columna As Variant, Rango_Columna As Range) As Variant Dim f As Variant, c As Variant f = Application.WorksheetFunction.Match(Valor_Fila, Rango_Fila, 0) c = Application.WorksheetFunction.Match(Valor_Columna, Rango_Columna, 0) IB·BuscarFC = Application.WorksheetFunction.Index(Rango_Busqueda, f, c) End Function

Macro para convertir todas las hojas de un libro Excel a PDFs Individuales

Código: Sub Hojas·a·PDFs()     Application.ScreenUpdating = False     Dim hoja As Worksheet, rutaCarpeta As Variant     rutaCarpeta = Application.FileDialog(msoFileDialogFolderPicker).Show     If rutaCarpeta = -1 Then         rutaCarpeta = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)         For Each hoja In Worksheets             hoja.ExportAsFixedFormat Type:=xlTypePDF, _                 Filename:=rutaCarpeta & "\" & hoja.Name & ".pdf", _                 Quality:=xlQualityStandard, _                 IncludeDocProperties:=True, _                 IgnorePrintAreas:=False, _                 OpenAfterPublish:=False         Next hoja...

FUNCIONES BÁSICAS SEGÚN EL COLOR DE RELLENO DE LA CELDA APLICADO MANUALMENTE

  Código: Function IB·PromedioColor(Celda·con·Color·a·Contar As Range, Rango As Range) As Double     Dim c As Range, S As Double, n As Long     For Each c In Rango         If c.Interior.Color = Celda·con·Color·a·Contar.Interior.Color Then             S = S + c.Value             n = n + 1         End If     Next c     If n > 0 Then         IB·PromedioColor = S / n     Else         IB·PromedioColor = 0     End If End Function Function IB·RecuentoColor(Celda·con·Color·a·Contar As Range, Rango As Range) As Double     Dim c As Range, R As Long     R = 0     For Each c In Rango         If c.Interior.Color = Celda·con·Color·a·Contar.Interior.Color Then             R = R + 1         End If ...

Macro para obtener los números primos en Excel

Código: Sub IB·NúmerosPrimos() Dim n As Long, p() As String, x As Long, i As Long, b As Boolean, u As Long, r As Range, c As Range On Error Resume Next n = Application.InputBox("Introduce el número límite:", "INGENIERÍA & BURÓTICA", Type:=1) On Error GoTo 0 If n <= 1 Then Exit Sub End If On Error Resume Next Set c = Application.InputBox("Selecciona la celda a partir de la cual se enlistarán los números primos", "INGENIERÍA & BURÓTICA", Type:=8) On Error GoTo 0 If c Is Nothing Then Exit Sub End If ReDim p(n - 1) u = 0 For x = 2 To n b = True For i = 2 To Int(x ^ 0.5) + 1 If x Mod i = 0 Then b = False Exit For End If Next i If b Or x = 2 Then p(u) = CStr(x) u = u + 1 End If Next x ReDim Preserve p(u - 1) Set r = c.Resize(u, 1) r.Value = WorksheetFunction.Transpose(p) MsgBox "Existen " & u & " números primos hasta " & n, , "INGENIERÍA & BURÓTICA" End Sub

Hallar el valor menos repetido en Excel ya sea este un número, texto o alfanumérico

La función UDF (User-Defined Function) llamada "IB·INFRECUENTE" es una función desarrollada en Visual Basic for Applications (VBA) para ser utilizada en Microsoft Excel para encontrar el valor menos frecuente en un rango de celdas especificado, el valor puede ser numérico, texto o alfanumérico. Si hay varios valores con la misma frecuencia mínima, la función IB· INFRECUENTE  devolverá todos los valores empatados separados por punto y coma (;) en caso de empate. Sintaxis:  La sintaxis de la función "IB·INFRECUENTE" es la siguiente: = IB·INFRECUENTE (Rango) Parámetros: La función tiene un parámetro:  Rango  (obligatorio): Representa el rango de celdas en el que se desea encontrar el valor menos frecuente. Código:  Function IB·INFRECUENTE(Rango As Range) As Variant     Dim v As Object, c As Range, l As Variant, m As Long, n As String     Set v = CreateObject("Scripting.Dictionary")     For Each c In Rango      ...

Hallar el valor más repetido en Excel ya sea este un número, texto o alfanumérico

La función UDF (User-Defined Function) llamada "IB·MODA" es una función desarrollada en Visual Basic for Applications (VBA) para ser utilizada en Microsoft Excel para encontrar la moda (valor más frecuente) en un rango de celdas especificado, el valor puede ser numérico, texto o alfanumérico, a diferencia de la función MODA que solo admite valores numéricos. Si hay varios valores con la misma frecuencia máxima, la función IB·MODA devolverá todos los valores empatados separados por punto y coma (;) en caso de empate. Sintaxis:  La sintaxis de la función "IB·MODA" es la siguiente: = IB·MODA (Rango) Parámetros: La función tiene un parámetro:  Rango (obligatorio): Representa el rango de celdas en el que se desea encontrar la moda. Código:  Function IB·MODA(Rango As Range) As Variant     Dim x As Object, y As Range, z As Long, m As Variant, n As String     Set x = CreateObject("Scripting.Dictionary")     For Each y In Rango   ...