View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Code works but goes into endless loop and crashes

Hi again,

Am Wed, 9 Oct 2013 07:59:13 +0200 schrieb Claus Busch:

If Not rngPN Is Nothing Then
For i = 14 To 6 Step -1
If .Cells(rngPN.Row, i) < "" Then
c.Offset(0, 1) = .Cells(rngPN.Row, i)
Exit For
End If
Next
c.Offset(0, 2) = .Cells(rngPN.Row, WorksheetFunction. _
CountBlank(.Range(.Cells(rngPN.Row, 1), .Cells(rngPN.Row, 5))) + 1)
End If


or try it with an array:

If Not rngPN Is Nothing Then
ReDim varOut(1 To 1, 1 To 14)
varOut = .Range(.Cells(rngPN.Row, 1), .Cells(rngPN.Row, 14))
For i = 14 To 1 Step -1
If varOut(1, i) < "" Then
c.Offset(0, 1) = varOut(1, i)
Exit For
End If
Next
For i = 1 To 14
If varOut(1, i) < "" Then
c.Offset(0, 2) = varOut(1, i)
Exit For
End If
Next
End If

you can also look again to the workbook in Skydrive
There are now 2 codes:
ListNewPNClaus and ListNewPNClaus2


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2