Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Select Columns based on cell value

Hoping I can explain this correctly. I have multiple
spreadsheets in the same workbook that are all the same
but contain different information. I am trying to get a
seperate sheet to look at all other worksheets and if a
cell contains a certain value, then it will copy that
column into the new sheet.

Example Data: This is the column view of two sheets
SHEET1
ColA ColB ColC ColD
Red Blue Red Green
1 2 3 4

SHEET2
ColA ColB ColC ColD
Blue Red Blue Green
1 6 3 4


I would like SHEET3 to contain the columns above that
contain red in the first cell so new sheet would look like:

ColA ColB ColC
Red Red Red
1 3 6

Is there a way to do this programatically? If so any
assistance would be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Select Columns based on cell value

Sorry, could you please explain the logic? Why in sheet3, Column A = 1, Column B = 3, Column C = 6?

I guess Column A = 1, Column B = 6, Column C = 3... If so, I understand. If not, please explain the logic.

Anyway, assuming what I though is correct. The following custom function can solve your problem.

'------------------------------------------------------------------------
Function SUMIF3D(ByVal sum_range As range, ByVal compare_range As range, ByVal find_value)
Dim s As Object, tmp$, tmp2$
Application.Volatile
tmp = sum_range.Cells(1).Address(False, False)
tmp2 = compare_range.Cells(1).Address(False, False)

For Each s In sum_range.Parent.Parent.Worksheets
If s.Name < sum_range.Parent.Name Then
If s.range(tmp2).Value = find_value Then
SUMIF3D = Application.Sum(s.range(tmp)) + SUMIF3D
End If
End If
Next
End Function
'---------------------------------------------------------------

sum_range = the address of the cell you want to pick out in all worksheets. (A2 in your example)
compare_range = the address of the cell you want to compare in all worksheets. (A1 in your example)
find_value = the value which, if found in "compare_range", pick out the corresponding value in "sum_range" (RED in your example)

In Sheet3, cell A1, you type "Red".
In cell A2, you type:
=SUMIF3D(A2,A1,A1)

Then, you can drag the formula across to the cells on the right.

You may note the, instead of just "picking the values", it sums the values which satisfy the criteria.

Regards,
Edwin Tam




-----
wrote: -----

Hoping I can explain this correctly. I have multiple
spreadsheets in the same workbook that are all the same
but contain different information. I am trying to get a
seperate sheet to look at all other worksheets and if a
cell contains a certain value, then it will copy that
column into the new sheet.

Example Data: This is the column view of two sheets
SHEET1
ColA ColB ColC ColD
Red Blue Red Green
1 2 3 4

SHEET2
ColA ColB ColC ColD
Blue Red Blue Green
1 6 3 4


I would like SHEET3 to contain the columns above that
contain red in the first cell so new sheet would look like:

ColA ColB ColC
Red Red Red
1 3 6

Is there a way to do this programatically? If so any
assistance would be appreciated.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
graph based on the city i select in a particular cell Nikhil Charts and Charting in Excel 1 May 26th 09 01:19 PM
Select a cell based on an other cell's value wally_91 Excel Worksheet Functions 4 March 13th 08 12:24 AM
How do I Select Multiple Non Adjacent Rows based on a cell value? avalynch Excel Worksheet Functions 2 October 1st 06 07:45 PM
how can I select a range of cells based on a value of a cell? grigoras victor Excel Discussion (Misc queries) 1 June 26th 06 04:55 PM
Select a range of columns based on active cell Tom Ogilvy Excel Programming 0 November 10th 03 05:09 PM


All times are GMT +1. The time now is 11:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"