PC Review


Reply
Thread Tools Rate Thread

Copy Headings based on Cell Value

 
 
Jeff Gross
Guest
Posts: n/a
 
      5th Jun 2009
I have up to 300 rows of data with 11 columns on sheet "Data Sort 1". Column
A is filled based on some code running. Columns B-K may or may not have data
based on the fact that all of these cells have an IF formula.

What I need the data to do is search for data in the cell of each row. If
there is data, then enter the column heading on a different page ("Data Sort
1b"). The data would look like on the original sheet:

A B C D
E
Op # Op Desc Mech Risk Electr Risk Haz
Risk

10 test 1 elec 1
haz 1
10 test 2 mech 1
haz 2
10 test 3 mech 2 elec 2
10 test 4 elec 3


I need it to look like this on the second sheet in column C starting at row 2:

Electr Risk
Haz Risk
Mech Risk
Haz Risk
Mech Risk
Electr Risk
Electr Risk

Thanks for any help.
 
Reply With Quote
 
 
 
 
Jeff Gross
Guest
Posts: n/a
 
      5th Jun 2009
Here is the result I figured out:

Sheets("Data Sort 1b").Activate
With SourceSht
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
SourceRow = 2
DestRow = 2
SourceCol = 3
DestCol = 3
Do While .Range("A" & SourceRow) <> ""
For Colcount = 3 To LastCol
If Trim(.Cells(SourceRow, Colcount)) <> "" Then
HazardCategory = .Cells("1", Colcount).Value
DestSht.Range("C" & DestRow) = HazardCategory
DestRow = DestRow + 1
End If
Next Colcount
SourceRow = SourceRow + 1
Loop

Application.CutCopyMode = False
End With

"Jeff Gross" wrote:

> I have up to 300 rows of data with 11 columns on sheet "Data Sort 1". Column
> A is filled based on some code running. Columns B-K may or may not have data
> based on the fact that all of these cells have an IF formula.
>
> What I need the data to do is search for data in the cell of each row. If
> there is data, then enter the column heading on a different page ("Data Sort
> 1b"). The data would look like on the original sheet:
>
> A B C D
> E
> Op # Op Desc Mech Risk Electr Risk Haz
> Risk
>
> 10 test 1 elec 1
> haz 1
> 10 test 2 mech 1
> haz 2
> 10 test 3 mech 2 elec 2
> 10 test 4 elec 3
>
>
> I need it to look like this on the second sheet in column C starting at row 2:
>
> Electr Risk
> Haz Risk
> Mech Risk
> Haz Risk
> Mech Risk
> Electr Risk
> Electr Risk
>
> Thanks for any help.

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      8th Jun 2009
pretty good
1.you don't need
Application.CutCopyMode = False
2.ColumnsCount needs the decimal ie .ColumnsCount
3. the sheet doesn't even need to be the active sheet



With Sheets("Data Sort 1b")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
SourceRow = 2
DestRow = 2
SourceCol = 3
DestCol = 3
Do While .Range("A" & SourceRow) <> ""
For Colcount = 3 To LastCol
If Trim(.Cells(SourceRow, Colcount)) <> "" Then
DestSht.Cells(DestRow,"C") = .Cells("1", Colcount).Value
DestRow = DestRow + 1
End If
Next Colcount
SourceRow = SourceRow + 1
Loop



"Jeff Gross" <(E-Mail Removed)> wrote in message
news:832F9DA9-7198-4B17-8CA3-(E-Mail Removed)...
> Here is the result I figured out:
>
> Sheets("Data Sort 1b").Activate
> With SourceSht
> LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
> SourceRow = 2
> DestRow = 2
> SourceCol = 3
> DestCol = 3
> Do While .Range("A" & SourceRow) <> ""
> For Colcount = 3 To LastCol
> If Trim(.Cells(SourceRow, Colcount)) <> "" Then
> HazardCategory = .Cells("1", Colcount).Value
> DestSht.Range("C" & DestRow) = HazardCategory
> DestRow = DestRow + 1
> End If
> Next Colcount
> SourceRow = SourceRow + 1
> Loop
>
> Application.CutCopyMode = False
> End With
>
> "Jeff Gross" wrote:
>
>> I have up to 300 rows of data with 11 columns on sheet "Data Sort 1".
>> Column
>> A is filled based on some code running. Columns B-K may or may not have
>> data
>> based on the fact that all of these cells have an IF formula.
>>
>> What I need the data to do is search for data in the cell of each row.
>> If
>> there is data, then enter the column heading on a different page ("Data
>> Sort
>> 1b"). The data would look like on the original sheet:
>>
>> A B C D
>> E
>> Op # Op Desc Mech Risk Electr Risk
>> Haz
>> Risk
>>
>> 10 test 1 elec 1
>> haz 1
>> 10 test 2 mech 1
>> haz 2
>> 10 test 3 mech 2 elec 2
>> 10 test 4 elec 3
>>
>>
>> I need it to look like this on the second sheet in column C starting at
>> row 2:
>>
>> Electr Risk
>> Haz Risk
>> Mech Risk
>> Haz Risk
>> Mech Risk
>> Electr Risk
>> Electr Risk
>>
>> Thanks for any help.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy a cell value based on search of another cell Pendal Microsoft Excel Worksheet Functions 1 12th Nov 2008 05:33 PM
Copy an entire row based on value in one cell SueJB Microsoft Excel Programming 3 3rd Feb 2008 11:38 AM
copy cell based on date =?Utf-8?B?RHJlYW1zdGFyXzE5NjE=?= Microsoft Excel Worksheet Functions 4 15th Jul 2007 07:59 AM
VAB to copy cell values into new Sheet, Overwrite if needed and based off of Cell Value in a column gumby Microsoft Excel Programming 4 14th Jul 2007 01:55 AM
Copy contents to cell based on value in second cell =?Utf-8?B?TWlrZSBDYXJwZW50ZXI=?= Microsoft Excel Misc 3 21st Apr 2006 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:20 AM.