code works on text and not on numbers

fawnlemur

New Member
Joined
Dec 9, 2018
Messages
29
Hi


The code copies the data on the master sheet (MasterData) and then takes the first cell on the list (Splitcode) and hides it using a filter and deletes all the other rows so only rows with that cell remain and renames the sheet as that cell.

Then goes down the list and makes a sheet for each cell on that list.

Code:
Sub SplitandFilterSheet()
Dim Splitcode As RangeSheets("Master").SelectSet Splitcode = Range("Splitcode")For Each cell In SplitcodeSheets("Master").Copy After:=Worksheets(Sheets.Count)ActiveSheet.Name = cell.ValueWith ActiveWorkbook.Sheets(cell.Value).Range("MasterData").AutoFilter Field:=6, Criteria1:="NOT EQUAL TO" & cell.Value, Operator:=xlFilterValues.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.DeleteEnd WithActiveSheet.AutoFilter.ShowAllDataNext cellEnd Sub


so on this instance it filters the 6th column to see if it matches the cell. so when I use te
xt on the 6th column and the list it works perfectly.

but when I use numbers it doesn't work at all and highlights this code:

Code:
[COLOR=#0A0A0A][FONT=Roboto]With ActiveWorkbook.Sheets(cell.Value).Range("MasterData")[/FONT][/COLOR]


anyone know how to make it work on numbers

Thank you
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Re: code works on text and not on numbers, please help me fix it!!

please ignore above code, this is the correct code:

Code:
[COLOR=#0A0A0A][FONT=Roboto]Sub SplitandFilterSheet()Dim Splitcode As Range
Sheets("Master").Select
Set Splitcode = Range("Splitcode")
For Each cell In Splitcode
Sheets("Master").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = cell.Value
With ActiveWorkbook.Sheets(cell.Value).Range("MasterData")
.AutoFilter Field:=6, Criteria1:="<>" & cell.Value, Operator:=xlFilterValues
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilter.ShowAllData
Next cell
End Sub[/FONT][/COLOR]
 
Upvote 0
Re: code works on text and not on numbers, please help me fix it!!

try
Code:
With ActiveWorkbook.Sheets(CStr(Cell.Value)).Range("MasterData")
 
Upvote 0
Re: code works on text and not on numbers, please help me fix it!!

You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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