Bypassing Error to next line while working on Excel workbook from Ms word

Muhammad_Bilal

New Member
Joined
Sep 1, 2017
Messages
14
My situation is I am opening Workbook from MS Word where I find some Text and delete entire Row of found Text.

To achieve that I am using Userform having Check-boxes and Buttons. The code below loop through all check-boxes and if checkbox.value (C.Value) Return True then it perform action by pressing CEEMEA_Button (For code see below).

I am getting Error "Run-time Error '13': Type mismatch" at

Code:
.Application.Cells.Find(What:=C.Caption, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

I want to bypass this Error to next line what should I do??? I tried `On Error Goto` but it did not work. Remember I am opening Excel workbook from Ms word.

Code:
Unload Me
Dim WB As Workbook
Set WB = Workbooks.Open("C:\Users\dell\Desktop\EMEA CEEMEA\EMEA CC FINAL LIST.xls")
Dim C As MSForms.Control
For Each C In Me.Controls
If TypeName(C) = "CheckBox" Then
If C.Value = True Then
If C.Caption = "Select All" Then
Else
 
With WB
    .Application.Sheets("Sheet2").Select
    .Application.Range("A1").Select
 
    .Application.Cells.Find(What:=C.Caption, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
 
    .Application.ActiveCell.Rows("1:1").EntireRow.Select
    .Application.Selection.Delete Shift:=xlUp
 
End With
 
End If
End If
End If
Next C
 
WB.Close SaveChanges:=True
Workbooks.Close
Set WB = Nothing
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Are you running this code from Word VBA?

If you are then things like ActiveCell really don't have any meaning, especially on their own with no worksheet/workbook qualification.

Try this.
Code:
Dim rngFnd As Range

    With WB.Sheets("Sheet2")
        Set rngFnd = .Cells.Find(What:=C.Caption, After:=.Range("A1"), LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
        If Not rngFnd Is Nothing Then
            rngFnd.EntireRow.Delete Shift:=xlUp
        End If
 
    End With
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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