Run-time error when running code in changeevent

vegaz

New Member
Joined
Feb 18, 2015
Messages
3
Hi guys,

I get run-time error -2147417848 (80010108)
Automation error
The object invoked has disconnected from its clients.

When I use
Code:
Application.EnableEvents = False
I do not get these errors, however, the macro won't work either.
I guess it has something to do with the ActiveSheet I am using?:eeek:

Code:
Sub FindTotalAmountOfRowsInColumn()
    Dim startCol As String
    Dim startRow As Long
    Dim lastrow As Long
    Dim lastCol As Long
    Dim myCol As String
    Dim ws, ws2 As Worksheet
    Dim Rng As Range
    Dim cell As Range
    
Application.ScreenUpdating = False
    Set ws2 = ActiveSheet 'Preserves a reference to the active sheet as ws2
    ThisWorkbook.Activate 'Makes this workbook the one that is displayed




Set ws = ThisWorkbook.Sheets("Sheet1")




With ws
    startCol = "B"
    startRow = 13
    lastrow = ws.Range(startCol & ws.Rows.count).End(xlUp).Row
    'lastCol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
    lastCol = ws2.UsedRange.Columns(ws2.UsedRange.Columns.count).Column


    myCol = GetColumnLetter(lastCol)


    Set Rng = ws.Range(startCol & startRow & ":" & myCol & lastrow)


    ws.Range("A8").Value = "ITEMCOUNT:" & Rng.Rows.count
      
End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

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