Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Naming cells using partial cell data

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
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!
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Naming cells using partial cell data

Ronny

I can not see where in your code you are setting the value for you
variable lastrow which looks like it would be equal to 0 or - 1


DavidC

I hate to say it but you have erred. Yoiu can use both column numbe
and column letters in the Cell Command

Cells(1,1)

or

cells(1,"a"

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Naming cells using partial cell data

DavidC -

Tried changing the "D" to a 4 and that didn't work.


mudraker -

I have failed to copy that here (Sorry!) :) - Just
before the For loop, I have this:

lastrow = ActiveSheet.Cells(Rows.Count, "E").End
(xlUp).Row

There is data in column E (column #5) as well.

I am using Excel 97 SR-2, and I haven't tried this on any
of the later versions to see if it's just Excel 97 or
not...

Ronny

-----Original Message-----
Ronny

I can not see where in your code you are setting the

value for your
variable lastrow which looks like it would be equal to 0

or - 1


DavidC

I hate to say it but you have erred. Yoiu can use both

column number
and column letters in the Cell Command

Cells(1,1)

or

cells(1,"a")


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Naming cells using partial cell data

ronny

I am using excel 97 and do not get the same error that you are.

You may be suffering from a broken line wrap command


try this code which is your code with line wrap added in at appropriat
places. This allows a single line of code to be spread over severa
continuose lines



Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.Count, _
"E").End(xlUp).Row

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
Nex

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Naming cells using partial cell data

mudraker -

Thanks for the help, but it still gave me the same error
message oddly enough...

Maybe it's just a bad installation. Unfortunately, the
installation is a work-related thing, so maybe I might
have to contact our help desk about this.


-----Original Message-----
ronny

I am using excel 97 and do not get the same error that

you are.

You may be suffering from a broken line wrap command


try this code which is your code with line wrap added in

at appropriate
places. This allows a single line of code to be spread

over several
continuose lines



Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.Count, _
"E").End(xlUp).Row

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


---
Message posted from http://www.ExcelForum.com/

.

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
Validation of partial data in a cell. Chris Excel Discussion (Misc queries) 2 August 8th 08 06:49 PM
Formula for Pulling partial data from one cell into another Jamie Excel Worksheet Functions 5 June 1st 07 12:35 AM
remove partial data from cell nanox Excel Worksheet Functions 2 April 4th 06 02:33 AM
combining partial data from 2 different cells Steven Excel Discussion (Misc queries) 1 May 28th 05 09:07 PM
Bringing partial data from one cell into another Jack Taylor Excel Worksheet Functions 2 April 5th 05 06:43 PM


All times are GMT +1. The time now is 08:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"