Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add to each number in a cell

Status
Not open for further replies.

Groves22

Technical User
Jan 29, 2009
102
US
Is there a way I can add to each unique number in a cell.

For example:

I have 00378 in a cell. Is there something I can do to add 5 to each number in that cell?

The end result would be 55823. It's in a mod 10 format when adding.

Thanks
 
FYI: This should be possible without VBA by using an array formula

But since we're talking about VBA, this should get you started:
Code:
For i = 1 To Len(Range("A1"))
    foo = foo & (Mid(Range("A1"), i, 1) + 5) Mod 10
Next i

Range("A2") = foo

[tt][blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Hey John...
Thanks for the tip. I wasn't quite sure what the "foo" was so I found another way using your VBA.
Code:
For j = 2 To 4005
k = 0
For i = 1 To Len(Cells(j, 2))
    Cells(j, 3 + k) = (Mid(Cells(j, 2), i, 1) + 5) Mod 10
    k = k + 1
Next i
Next j
Not the cleanest but it got the job done!
Thanks
 



foo is chaw.

Chaw is man chew.

Therefore, foo::man chew is TRUE


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top