Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Delete 1st character if string is longer than 6 characters

Hello,

I have a list of values in column C (275,372 cells) and would
like to know if there is a way to look at each cell and delete the 1st
character if the string is longer than 6 characters. Below is what
the before sample would look like.

009075
009130
0009767
010471
010489
011640
013373
013824
017424
019038
020634
020642
020663
0020711
020723

So the above list will look like this after:

009075
009130
009767
010471
010489
011640
013373
013824
017424
019038
020634
020642
020663
020711
020723



Thanks you for any help you can provide,

DIDS
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Delete 1st character if string is longer than 6 characters

Hello DIDS,

Am Wed, 11 Apr 2012 10:33:23 -0700 (PDT) schrieb DIDS:

I have a list of values in column C (275,372 cells) and would
like to know if there is a way to look at each cell and delete the 1st
character if the string is longer than 6 characters.


try:
Sub myString()
Dim LRow As Long
Dim c As Range

LRow = Cells(Rows.Count, 3).End(xlUp).Row
For Each c In Range("C1:C" & LRow)
If Len(c) 6 Then
c = Right(c, Len(c) - 1)
End If
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Delete 1st character if string is longer than 6 characters

Hi Claus Busch,


Your code worked perfectly. Thank you very much for your
assistance.


Thanks,

DIDS
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Delete 1st character if string is longer than 6 characters

On Wed, 11 Apr 2012 10:33:23 -0700 (PDT), DIDS wrote:

Hello,

I have a list of values in column C (275,372 cells) and would
like to know if there is a way to look at each cell and delete the 1st
character if the string is longer than 6 characters. Below is what
the before sample would look like.

009075
009130
0009767
010471
010489
011640
013373
013824
017424
019038
020634
020642
020663
0020711
020723

So the above list will look like this after:

009075
009130
009767
010471
010489
011640
013373
013824
017424
019038
020634
020642
020663
020711
020723



Thanks you for any help you can provide,

DIDS


Since your example only shows six or seven character values, I wonder if you really want exactly what you write.

If you want to reduce all of your entries to six characters (or less), you could use:
========================
Option Explicit
Sub SixMax()
Dim rSrc As Range, c As Range
Set rSrc = Range("A1", Cells(Rows.Count, "A").End(xlUp))
For Each c In rSrc
c.Value = Right(c.Value, 6)
Next c
End Sub
========================

If some entries are less than six, and some more, but you want all entries to be six characters, then you could use:

==========================
Sub SixExact()
Dim rSrc As Range, c As Range
Set rSrc = Range("A1", Cells(Rows.Count, "A").End(xlUp))
For Each c In rSrc
c.Value = Right("000000" & c.Value, 6)
Next c
End Sub
===========================

And if you really want to remove just one from the right if the length is longer than six (so an eight character string becomes 7; and a 7 character string becomes 6; then)

============================
Sub RemoveOne()
Dim rSrc As Range, c As Range
Set rSrc = Range("A1", Cells(Rows.Count, "A").End(xlUp))
For Each c In rSrc
c.Value = Mid(c.Value, IIf(Len(c.Text) 6, 2, 1))
Next c
End Sub
===========================
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Delete 1st character if string is longer than 6 characters

Hi Ron Rosenfeld,

Thank you very much for your assistance.


Thanks,

DIDS


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
How replace a character in a string of characters? Chet Excel Programming 6 December 6th 06 01:54 AM
Extracting a character from a string of characters Sue Excel Discussion (Misc queries) 6 October 30th 05 01:35 AM
Remove all characters following the first character in a string RC Excel Discussion (Misc queries) 5 August 30th 05 03:17 AM
String Not Longer Than 255 Characters in VBA? Quido Excel Programming 1 September 19th 04 06:29 PM
Delete characters from a string Ron[_18_] Excel Programming 7 February 19th 04 04:24 PM


All times are GMT +1. The time now is 06:24 PM.

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

About Us

"It's about Microsoft Excel"