Public Function patron(Optional referencia, Optional ultima) Dim objRegex As VBScript_RegExp_55.RegExp Dim colMatch As VBScript_RegExp_55.MatchCollection Dim vbsMatch As VBScript_RegExp_55.Match Dim colSubMatch As VBScript_RegExp_55.SubMatches Dim sMatchString As String Dim i, num, numT As Integer Set objRegex = New VBScript_RegExp_55.RegExp On Error GoTo ControlErrores objRegex.IgnoreCase = True objRegex.Global = True objRegex.Pattern = "[^A-Za-záéíóúÁÉÍÓÚ ]+" Set colMatch = objRegex.Execute(referencia) numT = colMatch.Count objRegex.Pattern = "[A-Za-záéíóúÁÉÍÓÚ ]+" Set colMatch = objRegex.Execute(referencia) num = colMatch.Count If numT = 0 And num >= 0 Then patron = 1 Else patron = 2 End If Exit Function ControlErrores: Select Case Err.Number Case 13 MsgBox ("sal por 13 Controerror ") Worksheets(ActiveSheet.Name).Range(ultima).Value = "" Exit Function Case 9 End Select End Function
Sub inicia() Application.EnableEvents = False Dim unaref, unerangos, unesec As Range Dim lahoja, lahojasec, lahojasecA As String Dim i, lafil, ban, borrador As Integer Dim encontrada As Boolean lahoja = ActiveSheet.Name Set mirango = Range(ActiveCell,ActiveCell.Cells(Selection.Rows.Count,selection.Columns.Count)) dosceldas = mirango.Address(RowAbsolute:=False, ColumnAbsolute:=False) For i = 1 To Sheets.Count If Sheets(i).Name = "sec" & ActiveSheet.Name Then ban = 1 End If Next i If ban <> 1 Then Range(dosceldas).Name = ActiveSheet.Name Set NewSheet = Sheets.Add(Type:=xlWorksheet, After:=Worksheets(Worksheets.Count)) NewSheet.Name = "sec" & lahoja Range(dosceldas).Name = ActiveSheet.Name Sheets.Item(Mid(ActiveSheet.Name, 4)).Activate Else Set unerangos = Union(Range(ActiveSheet.Name), mirango) unerangos.Name = ActiveSheet.Name lahojasecA = Replace(unerangos.Name, "Hoja", "secHoja") ActiveWorkbook.Names.Item("sec" & ActiveSheet.Name).RefersTo = lahojasecA End If If borrador = 0 Then mirango.Interior.Color = RGB(250, 250, 250) mirango.Borders.Color = RGB(105, 105, 105) For Each ciclo In Sheets.Item("sec" & ActiveSheet.Name).Range("sec" & ActiveSheet.Name).Cells ciclo.Value = "=patron(" & lahoja & "!" & ciclo.Address(RowAbsolute:=True, ColumnAbsolute:=True) & ")" Next Else mirango.Interior.Color = RGB(255, 252, 255) mirango.Borders.Color = RGB(208, 215, 229) For Each ciclo In Sheets.Item(lahoja).Range(dosceldas).Cells ciclo.Value = " " Next For Each ciclo In Sheets.Item("sec" & ActiveSheet.Name).Range(dosceldas).Cells ciclo.Value = "" Next End If Application.EnableEvents = True End Sub
Sub ActivaEV() Application.CellDragAndDrop = True Application.EnableEvents = True End Sub
Sub kalugi() Dim X, interBorra, unaref, unerangosA, unerangos, copiamirango, unesec As Range Dim donlimpio, donlimpioA, lahoja, paraReC, paraReR, finalRe As String Dim ban, MyPos, encontrado, numC, numR As Integer Application.DisplayInsertOptions = True Application.CutCopyMode = xlCopy Application.CellDragAndDrop = False lahoja = ActiveSheet.Name Set mirango = Range(ActiveCell, ActiveCell.Cells(Selection.Rows.Count, Selection.Columns.Count)) copiamirango = mirango dosceldas = mirango.Address(RowAbsolute:=False, ColumnAbsolute:=False) For i = 1 To Names.Count If Names.Item(i).Name = "A" & ActiveSheet.Name Then If Names.Item(i).Value = "=#N/A" Then Names.Item(i).Delete Names.Item("b" & ActiveSheet.Name).Delete Else MyPos = InStr(Names.Item(i).Name, "#¡REF!") End If ban = 1 End If Next i If ban <> 1 Then Range(mirango.Address).Name = "A" & ActiveSheet.Name Range(mirango.Address).Name = "B" & ActiveSheet.Name Range(mirango.Address).Name = "K" & ActiveSheet.Name ActiveWorkbook.Names.Item("K" & ActiveSheet.Name).RefersTo = "=" & ActiveSheet.Name & "!" & "$A$1" ActiveWorkbook.Names.Item("A" & ActiveSheet.Name).RefersTo = mirango ActiveWorkbook.Names.Item("B" & ActiveSheet.Name).RefersTo = mirango Else Set interBorra = Application.Intersect(Range(Names("A" & ActiveSheet.Name).Name), Range(mirango.Address)) If interBorra Is Nothing Then Set unerangos = Union(Range("A" & ActiveSheet.Name), mirango) ActiveWorkbook.Names.Item("A" & ActiveSheet.Name).RefersTo = unerangos ActiveWorkbook.Names.Item("B" & ActiveSheet.Name).RefersTo = unerangos Else For Each c In Worksheets(ActiveSheet.Name).Range("A" & ActiveSheet.Name).Cells For Each kk In Worksheets(ActiveSheet.Name).Range(interBorra.Address).Cells If kk.Address = c.Address Then encontrado = 1 Range(c.Address).Interior.Color = RGB(255, 252, 255) Range(c.Address).Borders.Color = RGB(208, 215, 229) Range("$A$1").Interior.Color = RGB(255, 252, 255) Range("$A$1").Borders.Color = RGB(208, 215, 229) Exit For Else encontrado = 0 End If Next If encontrado <> 1 Then Set unerangos = Union(Range("K" & ActiveSheet.Name), Range(c.Address)) ActiveWorkbook.Names.Item("K" & ActiveSheet.Name).RefersTo = unerangos End If Next X = ActiveWorkbook.Names.Item("K" & ActiveSheet.Name).RefersTo X = Replace(X, ActiveSheet.Name & "!$A$1,", "", 1, 1) ActiveWorkbook.Names.Item("A" & ActiveSheet.Name).RefersTo = X If ActiveWorkbook.Names.Item("A" & ActiveSheet.Name).Value = "=" & ActiveSheet.Name & "!#¡REF!" Then Names.Item("A" & ActiveSheet.Name).Delete Names.Item("B" & ActiveSheet.Name).Delete Names.Item("K" & ActiveSheet.Name).Delete Exit Sub End If If ActiveWorkbook.Names.Item("A" & ActiveSheet.Name).RefersTo = "=" & ActiveSheet.Name & "!$A$1" Then Names.Item("A" & ActiveSheet.Name).Delete Names.Item("B" & ActiveSheet.Name).Delete Names.Item("K" & ActiveSheet.Name).Delete Exit Sub End If Names.Item("K" & ActiveSheet.Name).Delete Range(mirango.Address).Name = "K" & ActiveSheet.Name ActiveWorkbook.Names.Item("K" & ActiveSheet.Name).RefersTo = "=" & ActiveSheet.Name & "!" & "$A$1" End If For i = 1 To Sheets.Count If Sheets(i).Name = ActiveSheet.Name Then For Each RR In Worksheets(ActiveSheet.Name).Range("A" & ActiveSheet.Name).Cells VueltaPat = patron(RR.Value) If VueltaPat = 1 Then End If If VueltaPat = 2 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If If VueltaPat = 0 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If Next End If Next i End If End Sub
Objetos en ThisWorkbook
Private Sub Workbook_SheetActivate(ByVal Sh As Object) Application.EnableEvents = False Application.EnableEvents = True End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) Application.EnableEvents = False Application.EnableEvents = True End Sub
Private Sub Workbook_SheetCalculate(ByVal Sh As Object) Application.EnableEvents = False Application.EnableEvents = True End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Application.EnableEvents = False Dim interSele As Range Dim eleven As Worksheet Dim i As Integer On Error GoTo 0 On Error Resume Next For i = 1 To Names.Count If Names.Item(i).Name = "A" & ActiveSheet.Name Then Set interSele = Application.Intersect(Range(Names("A"&ActiveSheet.Name).Name),Range(Target.Address)) If interSele Is Nothing Then Range(Names("A" & ActiveSheet.Name).Name).Interior.Color = RGB(255, 252, 255) Range(Names("A" & ActiveSheet.Name).Name).Borders.Color = RGB(208, 215, 229) interSele.Interior.Color = RGB(255, 252, 255) interSele.Borders.Color = RGB(208, 215, 229) interSele.Interior.Color = RGB(250, 250, 250) interSele.Borders.Color = RGB(105, 105, 105) Else Range(Names("A" & ActiveSheet.Name).Name).Interior.Color = RGB(250, 250, 250) Range(Names("A" & ActiveSheet.Name).Name).Borders.Color = RGB(105, 105, 105) interSele.Interior.Color = RGB(250, 250, 250) interSele.Borders.Color = RGB(105, 105, 105) Range(interSele.Address).Select End If Exit For End If Next i Application.EnableEvents = True End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) Application.EnableEvents = False Dim inter, RR As Range Dim MyPos, VueltaPat, i As Integer Dim otra As String On Error GoTo 0 On Error Resume Next sigue para Set inter = Application.Intersect(Range(Names("A" & ActiveSheet.Name).Name), Range(Target.Address)) If inter Is Nothing Then For i = 1 To Sheets.Count If Sheets(i).Name = ActiveSheet.Name Then otra = Target.Address For Each RR In Worksheets(ActiveSheet.Name).Range("A" & ActiveSheet.Name).Cells VueltaPat = patron(RR.Value, otra) If VueltaPat = 1 Then End If If VueltaPat = 2 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If If VueltaPat = 0 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If Next End If Next i Else For i = 1 To Sheets.Count If Sheets(i).Name = ActiveSheet.Name Then otra = Target.Address For Each RR In Worksheets(ActiveSheet.Name).Range("A" & ActiveSheet.Name).Cells VueltaPat = patron(RR.Value, otra) If VueltaPat = 1 Then End If If VueltaPat = 2 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If If VueltaPat = 0 Then Sheets.Item(ActiveSheet.Name).Range(RR.Address).Cells = "" End If Next End If Next i Worksheets(ActiveSheet.Name).Calculate Range("A" & ActiveSheet.Name).Calculate End If Application.EnableEvents = True End Sub
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) Dim intermous As Range Dim i As Integer For i = 1 To Names.Count If Names.Item(i).Name = "A" & ActiveSheet.Name Then Set intermous = Application.Intersect(Range(Names("A" & ActiveSheet.Name).Name),Range(Target.Address)) End If Next i If intermous Is Nothing Then Else Cancel = True End If If Target.Address = "$A:$A" Then Cancel = True End If End Sub