Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 385
Default Function or Code Needed

If I have 51 columns,each column is a state and each row has a status for
each state, "Y" or "N", is there a way I can insert a column prior to first
state column that could pull which state has a "Y" and list in the new column
?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default Function or Code Needed

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a status for
each state, "Y" or "N", is there a way I can insert a column prior to
first
state column that could pull which state has a "Y" and list in the new
column
?



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 385
Default Function or Code Needed

Each state has its own column, 50 columns in all. I would like to, lets say,
in column B, have the states that = "Y" in column B.

Example:
columns B C D E F
Row 1 AL AZ CA DE
Row 2 AL, CA, DE Y N Y Y
Row 3 AZ,CA N Y Y N



"Bernard Liengme" wrote:

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a status for
each state, "Y" or "N", is there a way I can insert a column prior to
first
state column that could pull which state has a "Y" and list in the new
column
?




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default Function or Code Needed

Very different problem!
With just four states we would get away with
=IF(C2="Y",C$1&",","")&IF(D2="Y",D$1&",","")&IF(E2 ="Y",E$1&",","")&IF(F2="Y",F$1&",","")
We would need some way to remove the final comma
Clearly with 50 states, the formula would grow to become unmanageable

I think a VBA approach is the only answer. As your ready to enter that
universe?
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
Each state has its own column, 50 columns in all. I would like to, lets
say,
in column B, have the states that = "Y" in column B.

Example:
columns B C D E F
Row 1 AL AZ CA DE
Row 2 AL, CA, DE Y N Y Y
Row 3 AZ,CA N Y Y N



"Bernard Liengme" wrote:

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them
still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a status
for
each state, "Y" or "N", is there a way I can insert a column prior to
first
state column that could pull which state has a "Y" and list in the new
column
?






  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default Function or Code Needed

Here is a VBA solution
You need to open the VB Editor, insert a module and paste the code below
into the module window
Then in B2 enter =YNString(B2:AZ2) and copy that formula down the column

If you need help with VBA begin with a visit to the site below and then come
back with questions
David McRitchie's site on "getting started" with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

best wishes


Option Base 1
Function YNstring(myrange)
Set mystates = Range("C1:AZ1")
mycount = myrange.Count
myflag = True
For J = 1 To mycount
If myrange(J) = "Y" Then
If myflag Then
YNstring = YNstring & mystates(J)
myflag = False
Else
YNstring = YNstring & "," & mystates(J)
End If
End If
Next J
End Function

--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
Each state has its own column, 50 columns in all. I would like to, lets
say,
in column B, have the states that = "Y" in column B.

Example:
columns B C D E F
Row 1 AL AZ CA DE
Row 2 AL, CA, DE Y N Y Y
Row 3 AZ,CA N Y Y N



"Bernard Liengme" wrote:

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them
still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a status
for
each state, "Y" or "N", is there a way I can insert a column prior to
first
state column that could pull which state has a "Y" and list in the new
column
?








  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 385
Default Function or Code Needed

Thank you , Benard. This is exactly what I was looking for. Can yoiu explain
what the "J" stands for in the code?

"Bernard Liengme" wrote:

Here is a VBA solution
You need to open the VB Editor, insert a module and paste the code below
into the module window
Then in B2 enter =YNString(B2:AZ2) and copy that formula down the column

If you need help with VBA begin with a visit to the site below and then come
back with questions
David McRitchie's site on "getting started" with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

best wishes


Option Base 1
Function YNstring(myrange)
Set mystates = Range("C1:AZ1")
mycount = myrange.Count
myflag = True
For J = 1 To mycount
If myrange(J) = "Y" Then
If myflag Then
YNstring = YNstring & mystates(J)
myflag = False
Else
YNstring = YNstring & "," & mystates(J)
End If
End If
Next J
End Function

--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
Each state has its own column, 50 columns in all. I would like to, lets
say,
in column B, have the states that = "Y" in column B.

Example:
columns B C D E F
Row 1 AL AZ CA DE
Row 2 AL, CA, DE Y N Y Y
Row 3 AZ,CA N Y Y N



"Bernard Liengme" wrote:

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them
still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a status
for
each state, "Y" or "N", is there a way I can insert a column prior to
first
state column that could pull which state has a "Y" and list in the new
column
?






  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default Function or Code Needed

It is called a 'counter' It starts at 1, the code between FOR & NEXT get
done, J increases by 1.
This loop goes non until J is the number of cells in B1:AZ1, I could have
used 50 for this but it was easier to test with a smaller data set
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
Thank you , Benard. This is exactly what I was looking for. Can yoiu
explain
what the "J" stands for in the code?

"Bernard Liengme" wrote:

Here is a VBA solution
You need to open the VB Editor, insert a module and paste the code below
into the module window
Then in B2 enter =YNString(B2:AZ2) and copy that formula down the column

If you need help with VBA begin with a visit to the site below and then
come
back with questions
David McRitchie's site on "getting started" with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

best wishes


Option Base 1
Function YNstring(myrange)
Set mystates = Range("C1:AZ1")
mycount = myrange.Count
myflag = True
For J = 1 To mycount
If myrange(J) = "Y" Then
If myflag Then
YNstring = YNstring & mystates(J)
myflag = False
Else
YNstring = YNstring & "," & mystates(J)
End If
End If
Next J
End Function

--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
Each state has its own column, 50 columns in all. I would like to, lets
say,
in column B, have the states that = "Y" in column B.

Example:
columns B C D E F
Row 1 AL AZ CA DE
Row 2 AL, CA, DE Y N Y Y
Row 3 AZ,CA N Y Y N



"Bernard Liengme" wrote:

Assuming states in A, yes-no in B
Insert new B column (right click the B heading and use Insert)
Now Y/N are in column C
In B1 =IF(C1="Y",A1,"") and copy this down the column
The quick way to do the copy is to double click B1's fill handle which
is
the small black square in lower right corner when call is selected.
That is a pair of double-quotes " with nothing between them
If you want to pick up that list and use elsewhere, you can change the
formula to text: select all of the entries in B; use Copy; with them
still
selected use Edit | Paste Special with Vales specified
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Jennifer" wrote in message
...
If I have 51 columns,each column is a state and each row has a
status
for
each state, "Y" or "N", is there a way I can insert a column prior
to
first
state column that could pull which state has a "Y" and list in the
new
column
?








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
CODE Assistance needed PLEASE please please N.F[_2_] Excel Discussion (Misc queries) 0 July 9th 07 08:36 PM
Help needed with VBA code Sam Hill Excel Discussion (Misc queries) 1 May 9th 06 02:29 PM
VBA code help needed Martin Excel Discussion (Misc queries) 3 April 28th 06 09:28 AM
VLOOKUP code needed please j4ymf Excel Worksheet Functions 4 March 12th 06 07:48 PM
formula / code help needed Paul Watkins Excel Discussion (Misc queries) 2 March 16th 05 08:27 PM


All times are GMT +1. The time now is 10:23 PM.

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"