Copy from all sheets except one

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I wanna copy from all sheets in my workbook except one of them.
How do I fix this loop in the code below?

Code:
[COLOR=#333333][INDENT]Sub AnotherLoop_1063452()
Dim r As Range, rng As Range, rng1 As Range, b As Boolean
Dim arr As Variant
Application.ScreenUpdating = False

Set rng = Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row)
b = False
arr = Split(Application.InputBox("Please enter two 2-digit numbers separated by a comma."), ",")
If UBound(arr) <> 1 Then
    MsgBox "Your entry is invalid. Please try again."
    Exit Sub
End If

For Each r In rng
    If InStr(r.Value, arr(0)) > 0 And InStr(r.Value, arr(1)) > 0 Then
        b = True
        On Error GoTo nxt
        Set rng1 = Application.Union(rng1, r)
    End If
Next r
If b = True Then
'    rng.Rows.Hidden = True
'    rng1.EntireRow.Hidden = False
'    ActiveWindow.ScrollRow = rng1.Row
    rng1.EntireRow.Copy
    'Sheets.Add after:=Sheets(Sheets.Count)
    Sheets("Sheet2").Paste
Else
    MsgBox "No match found."
End If

Exit Sub
nxt:
    Set rng1 = r
    On Error GoTo 0
    Resume Next
End Sub
[/INDENT]
[/COLOR]
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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