Macro bugging when using declared variable "Cl.value" to find worksheet name

Status
Not open for further replies.

diygail123

New Member
Joined
Oct 24, 2018
Messages
25
Hi

Can anyone tell me how to stop the code below bugging at the Sheets(Cl.Value).Activate
The filename when I hover over CL.Value is 5837, and this does exist in the worksheet, I have tested by entering "5837" rather than Cl.value and the code runs fine!

Any help much appreciated.


Code:
 Sub CopyFltr()

'DECLARE VARIABLES
   Dim Ws As Worksheet
   Dim Cl As Range
   
   Application.ScreenUpdating = False
   Set Ws = Sheets("Import")
   
'FILTER ON EACH VENDOR ON IMPORT TAB
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("Scripting.dictionary")
     For Each Cl In Ws.Range("b5:b58")                                 'For Each Cl In Ws.Range("B5", Ws.Range("B" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Nothing
            Ws.Range("A4:O4").AutoFilter 2, Cl.Value
            Ws.AutoFilter.Range.Copy
            Sheets(Cl.Value).Activate                                                            'Sheets(Cl.Value).Activate
            Range("A6").PasteSpecial
                                                        'Ws.AutoFilter.Range.Copy Sheets(Cl.Value).Range("A4")
         End If
      Next Cl
   End With
   Ws.AutoFilterMode = False
   ActiveWindow.View = xlNormalView
   
   
   MsgBox ("Vendor tabs have now been updated")
   Sheets("Macros").Activate
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi,
try coercing your numeric value to a string

Rich (BB code):
Sheets(CStr(Cl.Value)).Activate

Dave
 
Upvote 0
Heres how you could do it:

Code:
Dim x As String

x = cl.Value
Sheets(x).Activate
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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