tags:

views:

47

answers:

2

I want to add a sequential number in column 1 (so A1, B1, c1, would be 1,2,3) WHEN I enter any data in Column 2. So if a cell doesn't have a value, nothing is entered in the other cell.

The end result should look like this.

A- 1    32
B- 2    18
C- 3    16

E- 5     20

It's for a box count and config.

I've tried a few things and I am missing a value. Can any one help please?

+1  A: 

Maybe this can help, just in the A1 cell use this formula:

Excel 2007

=IF(LEN(B1)>0;ROW(A1);"")

Excel 2010

=IF(LEN(B1)>0,ROW(A1),"")

And then fill down the cells with the formula. This will write the cell row when it finds anything and a zero when it doesnt:

1   test
2   test
3   test
0   
5   test
0   
7   test
oli206
If you change your formula to `=IF(LENGTH(B1)>0;ROW(A1);"")` (note the empty string/double quotes) it'll be empty if there isn't anything in B1.
mskfisher
Corrected, Thanks mskfisher! :)
oli206
its giving me a error. Ill have to look at it better
Fooz
Yes, I couldn't make this formula work in Excel 2010.
Leniel Macaferi
Well I guess you have an english version of excel, dont you? Here a screenshot of my excel executing the formula correctly (it's the 2007 one though): http://img842.imageshack.us/img842/2986/20100807005149.png Where "SI" means "IF", "LARGO" means "LENGTH" and "FILA" means "ROW" because I have the spanish version
oli206
@oli206: got it working now. The formula that worked for me is this: =IF(LEN(B1)>0,ROW(A1),"")
Leniel Macaferi
ops, i was making a guess when I said "length", i didnt remember that in the english version is just "len" thanks! :)
oli206
Thanks for the help.=IF(LEN(B1)>0,ROW(A1),"") works as intended.
Fooz
A: 

One way to tackle this problem would be to leverage the Worksheet_Change event. This way you do not need to have any formulas in your spreadsheet:

Private Sub Worksheet_Change(ByVal Target As Range)

    If Application.Intersect(Target, Range("B:B")) Is Nothing Then
        End
    End If

    Target.Offset(0, -1) = WorksheetFunction.Max(Range("A:A")) + 1

End Sub

To implement this code:

  1. In your workbook press ALT + F11 (this opens VBA editor)
  2. Open the Project Explorer (CTRL + R)
  3. Double-clik the sheet that you want the code to apply to e.g. Sheet1
  4. In the left-hand dropdown menu select Worksheet and in the right hand menu select Change
  5. Cut and paste the code provided

Hope this helps.

Remnant