PC Review


Reply
Thread Tools Rate Thread

Check & Convert cell Value if condition auto

 
 
SteveT
Guest
Posts: n/a
 
      25th Jun 2008
Hello,

Sheet 1, Column A is populated with Ref #s
I would macro to check value and alter (if) according to below:

LEN(VALUE) = 6 then "111"+VALUE
LEN(VALUE) = 7 then VALUE
VALUE already begins with "111" then VALUE

I believe an event macro in sheet is route.... that is as far as i can take
it.
Any help appreciated, I've searched for awhile but solution found not.

Thanks in advance.


 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      25th Jun 2008
Hi,

Right click your sheet tab, view code and paste this in and run it

Sub sonic()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
If Len(c) = 6 And Left(c.Value, 3) <> 111 Then
c.Value = 111 & c.Value
End If
Next
End Sub

Mike

"SteveT" wrote:

> Hello,
>
> Sheet 1, Column A is populated with Ref #s
> I would macro to check value and alter (if) according to below:
>
> LEN(VALUE) = 6 then "111"+VALUE
> LEN(VALUE) = 7 then VALUE
> VALUE already begins with "111" then VALUE
>
> I believe an event macro in sheet is route.... that is as far as i can take
> it.
> Any help appreciated, I've searched for awhile but solution found not.
>
> Thanks in advance.
>
>

 
Reply With Quote
 
SteveT
Guest
Posts: n/a
 
      25th Jun 2008
Thanks Mike... Is there anyway to automatically run upon user exiting the
cell ?

BR, Steven



"Mike H" wrote:

> Hi,
>
> Right click your sheet tab, view code and paste this in and run it
>
> Sub sonic()
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> Set myrange = Range("A1:A" & lastrow)
> For Each c In myrange
> If Len(c) = 6 And Left(c.Value, 3) <> 111 Then
> c.Value = 111 & c.Value
> End If
> Next
> End Sub
>
> Mike
>
> "SteveT" wrote:
>
> > Hello,
> >
> > Sheet 1, Column A is populated with Ref #s
> > I would macro to check value and alter (if) according to below:
> >
> > LEN(VALUE) = 6 then "111"+VALUE
> > LEN(VALUE) = 7 then VALUE
> > VALUE already begins with "111" then VALUE
> >
> > I believe an event macro in sheet is route.... that is as far as i can take
> > it.
> > Any help appreciated, I've searched for awhile but solution found not.
> >
> > Thanks in advance.
> >
> >

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      25th Jun 2008
Hi,

You could try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:a")) Is Nothing Then
If Len(Target) = 6 And Left(Target.Value, 3) <> 111 Then
Target.Value = 111 & Target.Value
End If
End If


Mike

"SteveT" wrote:

> Thanks Mike... Is there anyway to automatically run upon user exiting the
> cell ?
>
> BR, Steven
>
>
>
> "Mike H" wrote:
>
> > Hi,
> >
> > Right click your sheet tab, view code and paste this in and run it
> >
> > Sub sonic()
> > lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> > Set myrange = Range("A1:A" & lastrow)
> > For Each c In myrange
> > If Len(c) = 6 And Left(c.Value, 3) <> 111 Then
> > c.Value = 111 & c.Value
> > End If
> > Next
> > End Sub
> >
> > Mike
> >
> > "SteveT" wrote:
> >
> > > Hello,
> > >
> > > Sheet 1, Column A is populated with Ref #s
> > > I would macro to check value and alter (if) according to below:
> > >
> > > LEN(VALUE) = 6 then "111"+VALUE
> > > LEN(VALUE) = 7 then VALUE
> > > VALUE already begins with "111" then VALUE
> > >
> > > I believe an event macro in sheet is route.... that is as far as i can take
> > > it.
> > > Any help appreciated, I've searched for awhile but solution found not.
> > >
> > > Thanks in advance.
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check a condition and write another cell bakbuk Microsoft Excel Worksheet Functions 0 16th Feb 2010 05:48 AM
Check Box On Condition Mike Microsoft Access Reports 1 8th Jan 2010 04:24 PM
Display in same cell lbs(kgs) using formula to auto-convert lbs =?Utf-8?B?SWFuIEJ1cm5ieQ==?= Microsoft Excel New Users 1 2nd Mar 2007 11:43 PM
auto change cell text colour resulting from a condition =?Utf-8?B?Q2hpbmFtYW4=?= Microsoft Excel Worksheet Functions 2 14th Dec 2006 01:19 AM
Condition is true in one cell, give me same condition in another T. Harris Microsoft Excel Misc 1 28th May 2004 08:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.