PC Review


Reply
Thread Tools Rate Thread

brain fart, need help

 
 
Matthew Dyer
Guest
Posts: n/a
 
      18th Aug 2012
I need to run a loop that replaces the last charachter ("0") of every cell in column d with a 1. Since the data stored in each cell is very long, it is stored as text to prevent scientific notation nonsense. help...?
 
Reply With Quote
 
 
 
 
Auric__
Guest
Posts: n/a
 
      18th Aug 2012
Matthew Dyer wrote:

> I need to run a loop that replaces the last charachter ("0") of every
> cell in column d with a 1. Since the data stored in each cell is very
> long, it is stored as text to prevent scientific notation nonsense.
> help...?


If it's just the last character, then this will do it:
Dim cell As Range, x As String
For Each cell In Range("D1" & Cells.SpecialCells _
(xlCellTypeLastCell).Row)
x = cell.Value
If Len(x) Then
Mid(x, Len(x), 1) = "1"
cell.Value = "'" & x
End If
Next

There are other ways to do the "Mid" line, such as:
x = Right(x, Len(x) - 1) & "1"
....but the way I did it works just fine.

If it's the last "0" character, then do this:
Dim cell As Range, x As String, n As Long
For Each cell In Range("D1" & Cells.SpecialCells _
(xlCellTypeLastCell).Row)
x = cell.Value
n = InStrRev(x, "0")
If n Then
Mid(x, n, 1) = "1"
cell.Value = "'" & x
End If
Next

--
Aren't you supposed to be somewhere else?
 
Reply With Quote
 
 
 
 
isabelle
Guest
Posts: n/a
 
      18th Aug 2012
hi,

Sub test()
Dim c As Range
For Each c In Range("D1" & Range("D65536").End(xlUp).Row)
If c <> "" Then Range(c.Address) = Left(c, Len(c) - 1) & 1
Next
End Sub

--
isabelle



Le 2012-08-18 15:11, Matthew Dyer a écrit :
> I need to run a loop that replaces the last charachter ("0") of every cell


in column d with a 1. Since the data stored in each cell is very long, it is stored as text to prevent scientific notation nonsense. help...?
>

 
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
Need Help am Brain Dead today. =?Utf-8?B?S2hhbmpvaG4=?= Microsoft Excel Programming 5 17th Apr 2007 01:56 PM
Brain Dead: Need help with ???? WarrenC Microsoft Excel Worksheet Functions 3 25th Jul 2006 08:11 AM
Need collective brain power of the many =?Utf-8?B?UGFwcHk1Mw==?= Windows XP General 3 9th Dec 2004 09:57 PM
Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! -$- Windows XP Internet Explorer 2 21st Dec 2003 11:45 PM
Re: Why cop and brain surgeon removed my brain? Ignoramus28006 Microsoft Excel Discussion 0 16th Jul 2003 04:53 PM


Features
 

Advertising
 

Newsgroups
 


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