ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to remove last character of each value of an array (https://www.excelbanter.com/excel-programming/425016-how-remove-last-character-each-value-array.html)

Varun

How to remove last character of each value of an array
 
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

Ron Rosenfeld

How to remove last character of each value of an array
 
On Tue, 3 Mar 2009 16:58:01 -0800, Varun
wrote:

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

ryguy7272

How to remove last character of each value of an array
 
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---
--
RyGuy


"Varun" wrote:

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


Jacob Skaria

How to remove last character of each value of an array
 
Hi Varun

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

Jacob

"Varun" wrote:

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


Rick Rothstein

How to remove last character of each value of an array
 
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.

--
Rick (MVP - Excel)


"Varun" wrote in message
...
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



Rick Rothstein

How to remove last character of each value of an array
 
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.

--
Rick (MVP - Excel)


"Varun" wrote in message
...
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



Rick Rothstein

How to remove last character of each value of an array
 
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.

--
Rick (MVP - Excel)


"Varun" wrote in message
...
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



Jacob Skaria

How to remove last character of each value of an array
 
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..



All times are GMT +1. The time now is 12:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com