Sorting range based on data from another worksheet

yevlar

New Member
Joined
Apr 23, 2005
Messages
41
Okay - I need to sort Sheet 1 Col. B by using the data in Sheet 2 Col. A. (Sheet 2 col A contains text. Sheet 1 col. B is all formulas relating to the text in Sheet 2.) And again, I'd like to do this via a checkbox or option button or command button or something along those lines - where, when checked, it sorts Sheet1 colB by alphabetizing sheet2 colA; and when unchecked sorts all of Sheet1 by Sheet1 colA (which contians dates.)

Tried this code, but it didn't work:

Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then

Worksheets("Sheet1").Range("B4:B1000").Sort _
        Key1:=Worksheets("Sheet2").Range("A4")
        
Else
Worksheets("Sheet1").Range("A4:A1000").Sort _
        Key1:=Worksheets("Sheet1").Range("A4")
End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This is not going to be easy, but please give an example of the formulas in Sheet1 column B.
 

yevlar

New Member
Joined
Apr 23, 2005
Messages
41
All of the rows in Sheet 1 Col. B use INDIRECT to refer to the content from Sheet2 col. A (Sheet2 is called PASTE in this document.)

i.e.:

=IF(OR(INDIRECT("PASTE!A" & ROW())="",INDIRECT("PASTE!L" & ROW())="X"),"",INDIRECT("PASTE!A" & ROW()))
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
While you can sort a column containing those formulas if calculation is set to manual, pressing F9 will cause the results of the formulas to revert to what they were. That's because your formula uses the ROW() function, and a sort doesn't change it.

In short, it's not possible to sort a column of formulas that refer to cells outside of the sort range.
 

yevlar

New Member
Joined
Apr 23, 2005
Messages
41
I had a feeling. I read an older post that stated that Excel didn't like that sort of thing, but I figured I'd ask again.

Thanks for the help!
 

Forum statistics

Threads
1,136,990
Messages
5,678,983
Members
419,797
Latest member
ikethegenius

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
Top