Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default macro to update last character

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default macro to update last character

Sorry about the double post.I got an error the first time so didn't think it
got posted.
--
maryj


"maryj" wrote:

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default macro to update last character

Hi,

Try this. Change Sht variable to the name of your sheet

Sub last_Char()
Dim LastRow As Long
Dim MyRange As Range, c As Range
Set sht = Sheets("Sheet2") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "G").End(xlUp).Row
Set MyRange = sht.Range("G1:G" & LastRow)
For Each c In MyRange
c.Value = Left(c.Value, Len(c.Value) - 1) & _
Right(c.Value, 1) + 1
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"maryj" wrote:

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default macro to update last character

Hi,

On reflection I should have included a chack to ensure the rightmost
character was numeric

Sub last_Char()
Dim LastRow As Long
Dim MyRange As Range, c As Range
Set sht = Sheets("Sheet2") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "G").End(xlUp).Row
Set MyRange = sht.Range("G1:G" & LastRow)
For Each c In MyRange
If IsNumeric(Right(c.Value, 1)) Then
c.Value = Left(c.Value, Len(c.Value) - 1) & _
Right(c.Value, 1) + 1
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Hi,

Try this. Change Sht variable to the name of your sheet

Sub last_Char()
Dim LastRow As Long
Dim MyRange As Range, c As Range
Set sht = Sheets("Sheet2") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "G").End(xlUp).Row
Set MyRange = sht.Range("G1:G" & LastRow)
For Each c In MyRange
c.Value = Left(c.Value, Len(c.Value) - 1) & _
Right(c.Value, 1) + 1
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"maryj" wrote:

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default macro to update last character

Assuming the values are always stored in column G why don't you add (in any
other empty column) formula as follows:
=IF(NOT(ISBLANK(G1)),CONCATENATE(LEFT(G1,LEN(G1)-1),"2"),"")
The formula shows empty string if there is now value in column G and it also
assumes that the length of string in column G may vary.

Hope it helps.

Kind regards
IgorM

"maryj" wrote in message
...
We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will
always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default macro to update last character

Thanks Mike! Work like a dream!!!
--
maryj


"Mike H" wrote:

Hi,

Try this. Change Sht variable to the name of your sheet

Sub last_Char()
Dim LastRow As Long
Dim MyRange As Range, c As Range
Set sht = Sheets("Sheet2") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "G").End(xlUp).Row
Set MyRange = sht.Range("G1:G" & LastRow)
For Each c In MyRange
c.Value = Left(c.Value, Len(c.Value) - 1) & _
Right(c.Value, 1) + 1
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"maryj" wrote:

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default macro to update last character

Glad I could help and thanks for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"maryj" wrote:

Thanks Mike! Work like a dream!!!
--
maryj


"Mike H" wrote:

Hi,

Try this. Change Sht variable to the name of your sheet

Sub last_Char()
Dim LastRow As Long
Dim MyRange As Range, c As Range
Set sht = Sheets("Sheet2") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "G").End(xlUp).Row
Set MyRange = sht.Range("G1:G" & LastRow)
For Each c In MyRange
c.Value = Left(c.Value, Len(c.Value) - 1) & _
Right(c.Value, 1) + 1
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"maryj" wrote:

We are using Excel 2007. We have a large list of id numbers that will need
the last character changed from a 1 to 2. The length of the list will always
vary but will always be in Column G.

For example:
11323674US01
11321507US01
11378181US01
need to be updated to:
11323674US02
11321507US02
11378181US02

Thanks for your help!

--
maryj

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
Macro to update last character maryj Excel Programming 2 February 24th 10 12:15 AM
Help - macro messes up the character formating Ivaylo Excel Programming 3 February 5th 10 02:33 PM
Macro to delete 'tick' Character ryguy7272 Excel Programming 2 October 5th 07 12:39 PM
Hidden Character Find Macro Help mvyvoda Excel Programming 6 January 14th 06 08:06 PM
Setting character colour in a macro JC Excel Discussion (Misc queries) 7 February 23rd 05 09:20 AM


All times are GMT +1. The time now is 12:49 AM.

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

About Us

"It's about Microsoft Excel"