Macro crashing and closing excel

Beneindias

Board Regular
Joined
Jun 21, 2022
Messages
120
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi guys, I need some help.

I have a file with a few macros, and it was everything working as expected, but today my excel started crashing and closing when I run one of the macros.

I was making changes to the file, and the macro was working, but sudently, It started closing excel.

The code is this:

VBA Code:
Sub Checkboxes_Creation()

    Dim lastRow As Long
    Dim Sh As Worksheet
    Dim worksheet1 As String: worksheet1 = "Salarios" 'Salarios
    Dim PagoColumn As String: PagoColumn = "B"
    Dim StatusColumn As String: StatusColumn = "C"
    Dim LastRowColumn As String: LastRowColumn = "l:l" 'Include Entire Column.
    Dim HRnumber As Integer
    Dim table As ListObject
    Dim tableData, rowData As Range
    Dim countA As Integer
    
     
    Set Sh = ActiveSheet
    Set table = Sh.ListObjects("TabelaSalarios")
    Set tableData = table.DataBodyRange
        
    countA = 0
    
    With Sh
        'Número da última coluna da tabela
        lastRow = WorksheetFunction.countA(Range(LastRowColumn))
    End With
        
    For Each rowData In tableData.Rows
        'Checa se não há nenhuma checkbox na linha. O "+7", serve para ignorar as 7 linhas antes da tabela
        '(não consegui fazer com que adicionasse a checkbox na linha X da tabela, pelo que tive que fazer X + 7)
        If Not CheckBoxExists(Sh.Range(PagoColumn & rowData.Row)) Then
        
            With Sh.Range(PagoColumn & rowData.Row)
            
                'Criação da checkbox e suas definições na coluna B (Pago)
                With Sh.CheckBoxes.Add(Cells(rowData.Row, PagoColumn).Left, Cells(rowData.Row, PagoColumn).Top, 10, 10)
                    .Caption = ""
                    .Locked = False
                    .LockedText = False
                    .Value = xlOff
                    .LinkedCell = Cells(rowData.Row, StatusColumn).Address
                End With
                
                'Chama o código para centrar a Checkbox na célula
                Call CenterCheckbox
                
            End With
            
        End If
        countA = countA + 1
    Next
    
End Sub

The macro "CenterCheckbox" is not the problem here, because I already run it with no problem.

In my friends computer the macro runs with no error.

Apreciate all your help
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Ok. Deleted all cache and temporary files and now it's working again.

For now, the problem is solved.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top