How to remove last character of each value of an array

  • Thread starter Thread starter Varun
  • Start date Start date
V

Varun

Hi Folks,

I'd like to remove the last character of each value of an array (the last
character is a comma i.e. ,). Below is what I have come up with and it does
not work. The array name is logical_layer1...any pointers will be
appreciated.

Thanks.

For arraynumber = 1 To UBound(logical_layer1)
string1(arraynumber) = Right(logical_layer1(arraynumber), 1)
If string1(arraynumber) = "," Then
logical_layer1(arraynumber) = Left((logical_layer(arraynumber)),
Len((logical_layer(arraynumber)) - 1))
End If
Next arraynumber
 
Hi Folks,

I'd like to remove the last character of each value of an array (the last
character is a comma i.e. ,). Below is what I have come up with and it does
not work. The array name is logical_layer1...any pointers will be
appreciated.

Thanks.

For arraynumber = 1 To UBound(logical_layer1)
string1(arraynumber) = Right(logical_layer1(arraynumber), 1)
If string1(arraynumber) = "," Then
logical_layer1(arraynumber) = Left((logical_layer(arraynumber)),
Len((logical_layer(arraynumber)) - 1))
End If
Next arraynumber

Try this (not tested).




for arraynumber = lbound(logical_layer1) to ubound(logical_layer1)
if right(logical_layer(arraynumber),1) = "," then
logical_layer1(arraynumber) = _
Left(logical_layer(arraynumber), _
len(logical_layer(arraynumber)-1)
end if
next arraynumber

--ron
 
Maybe somethign like this:

Sub RemoveProvisionalFromEndOfCellText()
Const sSearch As String = "*,*"
Dim rCell As Range
Dim nLen As Long
If TypeOf Selection Is Range Then
nLen = Len(sSearch) - 2
With Selection
On Error GoTo ErrorExit
For Each rCell In Intersect(.Cells, _
..Parent.UsedRange.SpecialCells( _
xlCellTypeConstants, xlTextValues))
With rCell
If .Text Like sSearch Then _
..Value = Left(.Text, Len(.Text) - nLen)
End With
Next rCell
End With
End If
ErrorExit:
End Sub

Remember, backup your data before running any new macro for the first time!!!


Regards,
Ryan---
 
Hi Varun

Your code will work if you initialize 'string1(arraynumber)' to blank
within the For loop after each iteration. Please try.

Jacob
 
Can you give us some more information please. What data type (if any) is
your logical_layer1 array declared as? How was it populated (details
please)? Depending on the answers you give, you might not have to do a loop
at all.
 
Can you give us some more information please. What data type (if any) is
your logical_layer1 array declared as? How was it populated (details
please)? Depending on the answers you give, you might not have to do a loop
at all.
 
Can you give us some more information please. What data type (if any) is
your logical_layer1 array declared as? How was it populated (details
please)? Depending on the answers you give, you might not have to do a loop
at all.
 
Hi Varun

If you need to remove all commas from the text; you dont need to loop

Combine the arrray using a delimiter other than comma.
Replace all commas with Null string
Split the text back to array using the same delimiter

Cheers..
 
Back
Top