Excel VBA code below will replace the first or last character of the cell value.
Use a test workbook with dummy data, to test the VBA code.
Works fine on Excel 2010.
Sub replaceChar()
'Replace Last Character
Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long
'specify the column where the values will be changed
myColumn = 2
'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To iRow
On Error Resume Next
strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1
'left - will replace last character on the string
yCutString = Left(strCellValue, ilength)
' LastChar is the string that will be added to the end of the cell value
'Replace this with any desired value
zValue = yCutString + "LastChar"
'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue
'uncomment this line to replace the value with the processed string
'specify myColumn value where the new values will be stored
'Cells(i, myColumn).Value = zValue
Next i
'Display a message when the processed is done
MsgBox "done"
End Sub
============================
Sub replaceChar()
'Replace First Character
Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long
'specify the column where the values will be changed
myColumn = 2
'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To iRow
On Error Resume Next
strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1
'right - will replace first character on the string
yCutString = Right(strCellValue, ilength)
'FirstChar is the string that will be appended to the beginning of the string
'Replace this with any value
zValue = "FirstChar" + yCutString
'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue
'uncomment this line to replace the value with the processed string
'specify myColumn value where the new values will be stored
'Cells(i, myColumn).Value = zValue
Next i
'Display a message when the processed is done
MsgBox "done"
End Sub
Cheers!! Hope it helps..
=========================
Use a test workbook with dummy data, to test the VBA code.
Works fine on Excel 2010.
Sub replaceChar()
'Replace Last Character
Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long
'specify the column where the values will be changed
myColumn = 2
'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To iRow
On Error Resume Next
strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1
'left - will replace last character on the string
yCutString = Left(strCellValue, ilength)
' LastChar is the string that will be added to the end of the cell value
'Replace this with any desired value
zValue = yCutString + "LastChar"
'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue
'uncomment this line to replace the value with the processed string
'specify myColumn value where the new values will be stored
'Cells(i, myColumn).Value = zValue
Next i
'Display a message when the processed is done
MsgBox "done"
End Sub
============================
Sub replaceChar()
'Replace First Character
Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long
'specify the column where the values will be changed
myColumn = 2
'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To iRow
On Error Resume Next
strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1
'right - will replace first character on the string
yCutString = Right(strCellValue, ilength)
'FirstChar is the string that will be appended to the beginning of the string
'Replace this with any value
zValue = "FirstChar" + yCutString
'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue
'uncomment this line to replace the value with the processed string
'specify myColumn value where the new values will be stored
'Cells(i, myColumn).Value = zValue
Next i
'Display a message when the processed is done
MsgBox "done"
End Sub
Cheers!! Hope it helps..
=========================
Heaven's Dew Fall
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Android Catholic Rosary App - Guide
https://play.google.com/store/apps/details?id=com.myrosaryapp&hl=en-GB
Educational App for Android Kids:
Free Version:
https://play.google.com/store/apps/details?id=com.xmultiplication
Paid Version:
https://play.google.com/store/apps/details?id=com.letsmultiply
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Android Catholic Rosary App - Guide
https://play.google.com/store/apps/details?id=com.myrosaryapp&hl=en-GB
Educational App for Android Kids:
Free Version:
https://play.google.com/store/apps/details?id=com.xmultiplication
Paid Version:
https://play.google.com/store/apps/details?id=com.letsmultiply
Comments
Post a Comment