Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel challenge, please save a doctor some time!

I need to convert cells in one worksheet into 1's and 0's and
correlate it with a value.

For example, if this was my starting worksheet (which I'm provided
with):

RowA RowB=1 RowC=0
6 3 2
12 5 4
18 1 2

I want to convert the above worksheet into a worksheet that had 2
rows, one being the value of RowA above, and the other being either a
1 or a 0, depending on whether it was rowB or rowC, and the number of
rows equals the number in rowB or rowC above. So, this example would
convert to a new worksheet of:

RowA RowB
6 1
6 1
6 1
6 0
6 0
12 1
12 1
12 1
12 1
12 1
12 0
12 0
12 0
12 0
18 1
18 0
18 0

Does anyone know how to do this without having to enter each value
separately?

Thanks,
Frustrated Doctor

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Excel challenge, please save a doctor some time!

Try this:

Sub DrMacro()
Dim myRange As Range
Dim r As Range
Dim lRow As Long
Dim bRow As Long
Dim newSht As Worksheet

bRow = 2 '<~~~change as needed to identify where the first row of data is
lRow = Cells(Rows.Count, 1).End(xlUp).Row
Set myRange = Cells(1, 1)
Set myRange = myRange.Offset(bRow - 1, 0).Resize(lRow - bRow + 1, 1)

Set newSht = Sheets("Sheet2") '<~~~~change as needed
lrow1 = newSht.Cells(Rows.Count, 1).End(xlUp).Row
For Each r In myRange
If r.Offset(0, 1).Value 0 Then
For i = 1 To r.Offset(0, 1).Value
newSht.Cells(lrow1, 1).Value = r.Value
newSht.Cells(lrow1, 2).Value = 1
lrow1 = lrow1 + 1
Next i
End If
If r.Offset(0, 2).Value 0 Then
For i = 1 To r.Offset(0, 2).Value
newSht.Cells(lrow1, 1).Value = r.Value
newSht.Cells(lrow1, 2).Value = 0
lrow1 = lrow1 + 1
Next i
End If
Next r

End Sub

HTH,
Barb Reinhardt

" wrote:

I need to convert cells in one worksheet into 1's and 0's and
correlate it with a value.

For example, if this was my starting worksheet (which I'm provided
with):

RowA RowB=1 RowC=0
6 3 2
12 5 4
18 1 2

I want to convert the above worksheet into a worksheet that had 2
rows, one being the value of RowA above, and the other being either a
1 or a 0, depending on whether it was rowB or rowC, and the number of
rows equals the number in rowB or rowC above. So, this example would
convert to a new worksheet of:

RowA RowB
6 1
6 1
6 1
6 0
6 0
12 1
12 1
12 1
12 1
12 1
12 0
12 0
12 0
12 0
18 1
18 0
18 0

Does anyone know how to do this without having to enter each value
separately?

Thanks,
Frustrated Doctor


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
Excel Doctor Kassie Links and Linking in Excel 2 August 15th 05 08:25 PM
Excel Doctor Kassie Excel Worksheet Functions 2 August 15th 05 08:25 PM
Excel Doctor Kassie Excel Programming 2 August 15th 05 08:25 PM
Excel Doctor GLS Excel Worksheet Functions 2 July 22nd 05 05:09 PM
Excel Doctor GLS Links and Linking in Excel 0 July 22nd 05 08:14 AM


All times are GMT +1. The time now is 02:37 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"