View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
DavidC[_2_] DavidC[_2_] is offline
external usenet poster
 
Posts: 44
Default Naming cells using partial cell data

Try replace "D" with 4 in the cells(row_index),"D" part of
the routine. Cells needs to be defined as a row number
(rowindex) and a column number not the column name.

best of luck

DavidC
-----Original Message-----
I get the following error when I run this code:

-----
Error:

Run-time error '1004':
That name is not valid.
-----

Code:

Dim lastrow As Long
Dim row_index As Long

For row_index = lastrow - 1 To 1 Step -1
If Left(Cells(row_index, "D").Value, 4) < Left
(Cells(row_index + 1, "D").Value, 4) Then
Cells(row_index + 1, "D").Resize(2,
1).EntireRow.Insert (xlShiftDown)
Cells(row_index + 1, "C").FormulaR1C1
= "=SUMPRODUCT(--(LEFT(R1C4:R[-1]C4,4)=LEFT(R[-1]
C4,4)),R1C3:R[-1]C3)"
Cells(row_index + 1, "C").Font.ColorIndex = 3
Cells(row_index + 1, "C").Font.Bold = True
Cells(row_index + 1, "C").Font.Size = 14
Cells(row_index + 1, "C").Name = Left(Cells
(row_index, "D").Value, 4)
End If
Next

Debugging points to the last line in the for loop

(naming
the cell using the first four characters from the cell
above.)

Thanks in advance!
.