Referring to a Specific Range of Data in a Table

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a table on one sheet and I would like to refer to a subset of that data on another sheet. Specifically, I have performance data broken down into categories (80%+, 60-79.99%, and Under 60%) and I want to list all the data that fall under the 60-79.99% category.

This is what the table looks like:
1691346833801.png


I have been manually copying and pasting just the 60-79.99% data in the Performance column at the far right after filtering for it in another sheet so I end up with this:
1691346949423.png


I'd like to automate this by inserting formulas that will directly refer to the table and only display the data subset that is labeled 60-79.99% so I don't have to keep copying and pasting every week. Does anyone know if this is possible? I could just whip up a macro that will run the steps of filtering the table and copying/pasting where I want it to go for me, but I'm becoming a fan of using permanently set formulas to simply update cells for me.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I would just make a sheet for 60-79.99%.
Assuming columns are A - F.
Then just hide G and on.
Use this as a module.

Screenshotted working. The first names won't match the first letter of username. But you get the idea.

VBA Code:
Sub stuffs()
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim lastRow As Long
Dim i As Long
Dim targetRow As Long
    
Set wsSource = ThisWorkbook.Worksheets("Sheet1")
Set wsTarget = ThisWorkbook.Worksheets("Sheet2")

wsTarget.UsedRange.Offset(1).ClearContents    

lastRow = wsSource.Cells(wsSource.Rows.Count, "F").End(xlUp).Row
    

targetRow = 1
    

wsSource.Rows(1).Copy wsTarget.Rows(targetRow)
targetRow = targetRow + 1
    
For i = 2 To lastRow
If wsSource.Range("F" & i).Value >= 0.6 And wsSource.Range("F" & i).Value <= 0.7999 Then
            wsSource.Rows(i).Copy wsTarget.Rows(targetRow)
targetRow = targetRow + 1
End If
 Next i
   
    
End Sub


1691350147819.png


1691350258972.png



When I made mine, I made it run on save. So everytime you hit save, it will update.


Added this to ThisWorkbook:

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
   
stuffs
    
End Sub
 
Upvote 0
Updated.

This will create Sheet2 if it does not exist.
When creating or overwriting the output sheet, it will also copy over the formatting.
Results are then auto-sorted from high to low.

You could just make a sheet that will just keep a list of this range of performers.
Just change all the Sheet2's to something like 607999 or Mid. Every time you save, it will update that sheet. Same can be done for all the other performance ranges.


VBA Code:
Sub stuffs()
    Dim wsSource As Worksheet
    Dim wsTarget As Worksheet
    Dim lastRow As Long
    Dim i As Long
    Dim targetRow As Long
   

    Set wsSource = ThisWorkbook.Worksheets("Sheet1")
   

    On Error Resume Next
    Set wsTarget = ThisWorkbook.Worksheets("Sheet2")
    On Error GoTo 0
   
    If wsTarget Is Nothing Then

        Set wsTarget = ThisWorkbook.Worksheets.Add
        wsTarget.Name = "Sheet2"
    End If
   

    lastRow = wsSource.Cells(wsSource.Rows.Count, "F").End(xlUp).Row
   

    targetRow = 1
   

    If wsTarget.UsedRange.Rows.Count = 1 Then
        wsSource.Rows(1).Copy
        wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteFormats
        wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteColumnWidths
        wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        targetRow = targetRow + 1
    End If
   

    For i = 2 To lastRow
 
        If wsSource.Range("F" & i).Value >= 0.6 And wsSource.Range("F" & i).Value <= 0.7999 Then

            wsSource.Rows(i).Copy
            wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteFormats
            wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteColumnWidths
            wsTarget.Rows(targetRow).PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
            targetRow = targetRow + 1
        End If
    Next i
   

    With wsTarget.Sort
        .SortFields.Clear
        .SortFields.Add Key:=wsTarget.Range("F:F"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        .SetRange wsTarget.UsedRange
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
   

    wsTarget.Activate

End Sub
 
Upvote 0
I'd like to automate this by inserting formulas that will directly refer to the table
I note you have 365 on your account details, therefore the Filter() function should be available to you. If your second sheet is a range (not a table) but your original data is a table, then try the following (just change the table name from Table1 to whatever you called the table).
Sheet1
Book1
ABCDEFGHI
1TM NameDeptShiftDOHUSERIDPerf%On Std%Eff%Perfomance
2datadatadatadatadata79.70%datadata60-79.99%
3datadatadatadatadata65.90%datadataBelow 60%
4datadatadatadatadata59.00%datadataBelow 60%
5datadatadatadatadata65.90%datadata60-79.99%
6datadatadatadatadata65.90%datadata60-79.99%
7datadatadatadatadata65.90%datadata60-79.99%
8datadatadatadatadata65.90%datadata60-79.99%
9datadatadatadatadata65.90%datadata60-79.99%
10datadatadatadatadata45.00%datadataBelow 60%
11datadatadatadatadata95.00%datadata80%+
12datadatadatadatadata95.00%datadata80%+
13datadatadatadatadata95.00%datadata80%+
14datadatadatadatadata95.00%datadata80%+
15datadatadatadatadata62.50%datadata60-79.99%
16datadatadatadatadata62.50%datadata60-79.99%
17datadatadatadatadata62.50%datadata60-79.99%
18datadatadatadatadata62.50%datadata60-79.99%
Sheet1


Sheet2
Book1
ABCDEF
160-79.99%
2TM NameDeptShiftDOHUSERIDPerf%
3datadatadatadatadata79.70%
4datadatadatadatadata65.90%
5datadatadatadatadata65.90%
6datadatadatadatadata65.90%
7datadatadatadatadata65.90%
8datadatadatadatadata65.90%
9datadatadatadatadata62.50%
10datadatadatadatadata62.50%
11datadatadatadatadata62.50%
12datadatadatadatadata62.50%
Sheet2
Cell Formulas
RangeFormula
A3:F12A3=FILTER(FILTER(Table1,Table1[Perfomance]="60-79.99%"),{1,1,1,1,1,1,0,0,0})
Dynamic array formulas.
 
Upvote 0
Another way...
Book1
ABCDEF
160-79.99%
2TM NameDeptShiftDOHUSERIDPerf%
3datadatadatadatadata79.70%
4datadatadatadatadata65.90%
5datadatadatadatadata65.90%
6datadatadatadatadata65.90%
7datadatadatadatadata65.90%
8datadatadatadatadata65.90%
9datadatadatadatadata65.90%
10datadatadatadatadata62.50%
11datadatadatadatadata62.50%
12datadatadatadatadata62.50%
13datadatadatadatadata62.50%
Sheet2
Cell Formulas
RangeFormula
A3:F13A3=FILTER(Table1[[#All],[TM Name]:[Perf%]],(Table1[[#All],[Perf%]]>=0.6)*(Table1[[#All],[Perf%]]<=0.799),"")
Dynamic array formulas.
 
Upvote 0
Solution
Thanks kevin9999, this was exactly what I was looking for. My results came out perfectly!

Also thanks to noveske for taking time to offer a solution. I did try out your macro based solution and it worked well enough, but I wanted to learn a formula based method.
 
Upvote 0
Thanks kevin9999, this was exactly what I was looking for. My results came out perfectly!

Also thanks to noveske for taking time to offer a solution. I did try out your macro based solution and it worked well enough, but I wanted to learn a formula based method.
Happy to help, and thanks for the feedback 👍
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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