Assigning same numbers to different cells

onaga

New Member
Joined
May 7, 2011
Messages
2
Dear all,

i would like to assign the same number to different cells but following a certain order:
-Check B2:B250,000; if cells are bounded by zeros up and down; assign 1 to the adjacent cells in C, check the next cells bounded by zeros and assign 2 to the adjacent cells in C, continue in that order..otherwise leave as blank..see example below. how can I do this?

<table border="0" cellpadding="0" cellspacing="0" width="128"><col style="width:48pt" span="2" width="64"> <tbody><tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt; width:48pt" align="right" height="20" width="64">0</td> <td class="xl63" style="border-left:none;width:48pt" width="64"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">22</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">55</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">39</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">40</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">12</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">41</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">90</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">25</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">9</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">12</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">34</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> </tbody></table>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the board!

Try this formula and copy down:
Excel Workbook
AB
1HeaderHeader
250
30
4221
5151
6371
70
80
9142
10122
11192
120
Sheet1
Cell Formulas
RangeFormula
B2=IF(A2=0,"",IF(B1="",MAX($B$1:B1)+1,N(B1)))
 
Upvote 0
Try this macro

Code:
Sub atest()
Dim LR As Long, i As Long, j As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 3 To LR
    With Range("B" & i)
        If .Value <> 0 Then
             If .Offset(-1).Value = 0 Then j = j + 1
            .Offset(, 1).Value = j
        End If
    End With
Next i
End Sub
 
Upvote 0
Dear all,

i would like to assign the same number to different cells but following a certain order:
-Check B2:B250,000; if cells are bounded by zeros up and down; assign 1 to the adjacent cells in C, check the next cells bounded by zeros and assign 2 to the adjacent cells in C, continue in that order..otherwise leave as blank..see example below. how can I do this?

<table border="0" cellpadding="0" cellspacing="0" width="128"><col style="width:48pt" span="2" width="64"> <tbody><tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt; width:48pt" align="right" height="20" width="64">0</td> <td class="xl63" style="border-left:none;width:48pt" width="64"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">22</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">55</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">39</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">40</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">12</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">41</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">90</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">25</td> <td class="xl63" style="border-top:none;border-left:none" align="right">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">9</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">12</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">34</td> <td class="xl63" style="border-top:none;border-left:none" align="right">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt;border-top:none" align="right" height="20">0</td> <td class="xl63" style="border-top:none;border-left:none"> </td> </tr> </tbody></table>
Also, assuming headers in row 1...

In B2 enter and copy down:

=IF(A2,LOOKUP(BigNum,CHOOSE({1,2},0,LOOKUP(BigNum,$B$1:B1)))+IF(N(A1)=0,1,0),"")

BigNum is defined as referring to:

=9.99999999999999E+307
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

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
Back
Top