PC Review


Reply
Thread Tools Rate Thread

change values in a column

 
 
guy
Guest
Posts: n/a
 
      27th Sep 2007
The values in column J are displayed as 1, 2, 3, 4, ...., 9, 10, 11, ....
I need all the values that are less than 10 added with leading 0, which are
put into column L.
(actually i want the values in column J change themselves, but i want to see
the difference before and after change, so i put the new values in column L)
But the following codes failed to do so....
Pls help...
Thanks a lot!!

----------------------------------------------------------------------

Sub test()

Dim i As Long
Dim st As String

For i = 2 To 150

Cells(i, 13) = TypeName(Cells(i, 10).Value)

If Cells(i, 10) < 10 Then
Cells(i, 11) = "yes"
st = "0" & Trim(Str(Cells(i, 10).Value))
Cells(i, 12).Value = st

End If

Next

End Sub



 
Reply With Quote
 
 
 
 
Bill Renaud
Guest
Posts: n/a
 
      27th Sep 2007
You could just format the cells to display numbers using a Custom Number
Format of "00".

In VBA code, this would look like the following:

Sub ShowLeadingZeroFormat()
Selection.NumberFormat = "00"
End Sub

--
Regards,
Bill Renaud



 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      27th Sep 2007
Like Bill said, you can simply change the number format. But that
will only be a visible change, not a real change. The value in the
cell will remain a single character. If you need tp physically place
a zero in the front, you'll need to change the number format of the
column to text. Something like this would work.
Sub test()
Dim i As Long
Dim st As String
Cells(1, 12).EntireColumn.NumberFormat = "@"
For i = 2 To 150
Cells(i, 13) = TypeName(Cells(i, 10).Value)
If Cells(i, 10) < 10 Then
Cells(i, 11) = "yes"
st = Trim("0" & Cells(i, 10).Text)
Cells(i, 12).Value = st
End If
Next
End Sub

guy wrote:
> The values in column J are displayed as 1, 2, 3, 4, ...., 9, 10, 11, ....
> I need all the values that are less than 10 added with leading 0, which are
> put into column L.
> (actually i want the values in column J change themselves, but i want to see
> the difference before and after change, so i put the new values in column L)
> But the following codes failed to do so....
> Pls help...
> Thanks a lot!!
>
> ----------------------------------------------------------------------
>
> Sub test()
>
> Dim i As Long
> Dim st As String
>
> For i = 2 To 150
>
> Cells(i, 13) = TypeName(Cells(i, 10).Value)
>
> If Cells(i, 10) < 10 Then
> Cells(i, 11) = "yes"
> st = "0" & Trim(Str(Cells(i, 10).Value))
> Cells(i, 12).Value = st
>
> End If
>
> Next
>
> End Sub


 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      27th Sep 2007
If you want to simply apply the changes/formatting to the existing
records, you could use this:
Sub test()
Dim i As Long
Cells(1, 10).EntireColumn.NumberFormat = "@"
For i = 2 To 150
Cells(i, 10).Value = _
Format(Cells(i, 10).Value, "00")
Next
End Sub

guy wrote:
> The values in column J are displayed as 1, 2, 3, 4, ...., 9, 10, 11, ....
> I need all the values that are less than 10 added with leading 0, which are
> put into column L.
> (actually i want the values in column J change themselves, but i want to see
> the difference before and after change, so i put the new values in column L)
> But the following codes failed to do so....
> Pls help...
> Thanks a lot!!
>
> ----------------------------------------------------------------------
>
> Sub test()
>
> Dim i As Long
> Dim st As String
>
> For i = 2 To 150
>
> Cells(i, 13) = TypeName(Cells(i, 10).Value)
>
> If Cells(i, 10) < 10 Then
> Cells(i, 11) = "yes"
> st = "0" & Trim(Str(Cells(i, 10).Value))
> Cells(i, 12).Value = st
>
> End If
>
> Next
>
> End Sub


 
Reply With Quote
 
guy
Guest
Posts: n/a
 
      28th Sep 2007
thank you so much!

"JW" <(E-Mail Removed)>
???????:(E-Mail Removed)...
> Like Bill said, you can simply change the number format. But that
> will only be a visible change, not a real change. The value in the
> cell will remain a single character. If you need tp physically place
> a zero in the front, you'll need to change the number format of the
> column to text. Something like this would work.
> Sub test()
> Dim i As Long
> Dim st As String
> Cells(1, 12).EntireColumn.NumberFormat = "@"
> For i = 2 To 150
> Cells(i, 13) = TypeName(Cells(i, 10).Value)
> If Cells(i, 10) < 10 Then
> Cells(i, 11) = "yes"
> st = Trim("0" & Cells(i, 10).Text)
> Cells(i, 12).Value = st
> End If
> Next
> End Sub
>
> guy wrote:
>> The values in column J are displayed as 1, 2, 3, 4, ...., 9, 10, 11, ....
>> I need all the values that are less than 10 added with leading 0, which
>> are
>> put into column L.
>> (actually i want the values in column J change themselves, but i want to
>> see
>> the difference before and after change, so i put the new values in column
>> L)
>> But the following codes failed to do so....
>> Pls help...
>> Thanks a lot!!
>>
>> ----------------------------------------------------------------------
>>
>> Sub test()
>>
>> Dim i As Long
>> Dim st As String
>>
>> For i = 2 To 150
>>
>> Cells(i, 13) = TypeName(Cells(i, 10).Value)
>>
>> If Cells(i, 10) < 10 Then
>> Cells(i, 11) = "yes"
>> st = "0" & Trim(Str(Cells(i, 10).Value))
>> Cells(i, 12).Value = st
>>
>> End If
>>
>> Next
>>
>> End Sub

>



 
Reply With Quote
 
guy
Guest
Posts: n/a
 
      28th Sep 2007
thanks!!

"Bill Renaud" <(E-Mail Removed)> ¼¶¼g©ó¶l¥ó·s»D:cf6dnQIT0Jtud2bbnZ2dnUVZ_s-(E-Mail Removed)...
> You could just format the cells to display numbers using a Custom Number
> Format of "00".
>
> In VBA code, this would look like the following:
>
> Sub ShowLeadingZeroFormat()
> Selection.NumberFormat = "00"
> End Sub
>
> --
> Regards,
> Bill Renaud
>
>
>



 
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
change values in a column dmack Microsoft Excel Misc 3 21st Apr 2008 11:26 PM
How can I change all negative values in a column to = 0? =?Utf-8?B?ZGJzYXZveQ==?= Microsoft Excel Worksheet Functions 6 21st Aug 2006 08:14 PM
How can I change all negative values in a column to = 0? =?Utf-8?B?ZGJzYXZveQ==?= Microsoft Excel Worksheet Functions 0 21st Aug 2006 07:52 PM
Change all values in an excel column at once? =?Utf-8?B?U24wd21hbg==?= Microsoft Excel Misc 4 25th Apr 2005 01:08 PM
Better way to apply change to column of values Tod Microsoft Excel Programming 3 16th Sep 2004 07:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 AM.