Selecting data from a master sheet into multiple tabs but master sheet should remain unaltered

Ryan1974

New Member
Joined
Sep 12, 2012
Messages
13
Hi,

I am using Excel 2010 and have the following code which is something I picked up in a forum and tweaked to my needs:
Sub parse_data()

Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer

vcol = 17 'CHANGE THE COLUMN NUMBER AS PER YOUR NEED

Set ws = Sheets("WOs")
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row

title = "A1" 'CHANGE THE TITLE ROW AS PER YOUR NEED
titlerow = ws.Range(title).Cells(1).Row
icol = ws.Columns.Count

ws.Cells(1, icol) = "Unique"

For i = 2 To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next

myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))

ws.Columns(icol).Clear

For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""

If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
End If

ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
Sheets(myarr(i) & "").Columns.AutoFit
Next

Sheets("RED").Tab.ColorIndex = 3
Sheets("AMBER").Tab.ColorIndex = 44
Sheets("GREEN").Tab.ColorIndex = 10

ws.AutoFilterMode = False
ws.Activate
End Sub


The code itself works fine, when running the macro I get three new tabs - Green, Amber, Red - with the relevant data being displayed.

The issue is that the Master Sheet instead of displaying all values, once the macro is run, displays the values of the last newly created sheet - meaning that if the last sheet created via macro is Green then the Master Sheet will only display Green values (or Red values or Amber values depending which is last).
The Master Sheet should remain unaltered showing all values (Red Amber Green or blank).
I have looked at another code I have which works fine where the Master Sheet is unaltered after Macro but that did not help me in this case (even when I copy paste the code and do the necessary changes - select a new input column - then I still get the same issue.)

Any help is appreciated.

R
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,216,028
Messages
6,128,391
Members
449,445
Latest member
JJFabEngineering

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