Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default brain fart, need help

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...?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default brain fart, need help

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:D" & 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:D" & 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?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default brain fart, need help

hi,

Sub test()
Dim c As Range
For Each c In Range("D1:D" & 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
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
Brain fart in simple subtraction Fritz W New Users to Excel 2 November 13th 09 05:22 PM
Brain Teaser John McCabe Excel Discussion (Misc queries) 2 July 31st 08 04:03 PM
Use Your Brain Pyball[_7_] Excel Programming 2 December 21st 03 01:08 AM
Use Your Brain Pyball[_5_] Excel Programming 0 December 18th 03 10:52 PM
Very basic question... I MUST be having a brain fart.... Phillips Excel Programming 1 November 26th 03 06:29 PM


All times are GMT +1. The time now is 01:01 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"