Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How to increment number using vb script

I have one excel spreed sheet on columnA one row A1 has "000002", on the 3rd
charactor I need to change to 2 for second row as "002002", then third row
will be as "004002", I need to increment 2 from the previous row until to the
end of row as"998002", how to run with the macro.
000002
002002
004002
006002
...........
998002

Thank you so much.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How to increment number using vb script

Lillian,

Dim a As Long
Dim MyCell As Range
Set MyCell = Range("C2") ' starting cell
a = 2000 ' starting value
Do While MyCell < "" ' stop on empty cell
MyCell = MyCell + a ' add a
Set MyCell = MyCell.Offset(1, 0) ' move down
a = a + 2000 ' increment a
Loop

this presumes the original values are all 2. It doesn't replace, it adds.

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Lillian" wrote in message
...
I have one excel spreed sheet on columnA one row A1 has "000002", on the
3rd
charactor I need to change to 2 for second row as "002002", then third row
will be as "004002", I need to increment 2 from the previous row until to
the
end of row as"998002", how to run with the macro.
000002
002002
004002
006002
..........
998002

Thank you so much.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default How to increment number using vb script

Do you really need a macro:

Put something like this in A1 and copy down:

=TEXT((ROW()-1)*2,"000")&"002"

As a macro:

Option Explicit
Sub testme()
With ActiveSheet.Range("a1:a500")
.NumberFormat = "General"
.Formula = "=TEXT((ROW()-1)*2,""000"")&""002"""
.NumberFormat = "@"
.Value = .Value
End With
End Sub

Lillian wrote:

I have one excel spreed sheet on columnA one row A1 has "000002", on the 3rd
charactor I need to change to 2 for second row as "002002", then third row
will be as "004002", I need to increment 2 from the previous row until to the
end of row as"998002", how to run with the macro.
000002
002002
004002
006002
..........
998002

Thank you so much.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How to increment number using vb script

Dave:

This work on both, thanks a lots. what is ROW()-1 means?


Lillian

"Dave Peterson" wrote:

Do you really need a macro:

Put something like this in A1 and copy down:

=TEXT((ROW()-1)*2,"000")&"002"

As a macro:

Option Explicit
Sub testme()
With ActiveSheet.Range("a1:a500")
.NumberFormat = "General"
.Formula = "=TEXT((ROW()-1)*2,""000"")&""002"""
.NumberFormat = "@"
.Value = .Value
End With
End Sub

Lillian wrote:

I have one excel spreed sheet on columnA one row A1 has "000002", on the 3rd
charactor I need to change to 2 for second row as "002002", then third row
will be as "004002", I need to increment 2 from the previous row until to the
end of row as"998002", how to run with the macro.
000002
002002
004002
006002
..........
998002

Thank you so much.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default How to increment number using vb script

If you put =row() in a worksheet cell, it returns the row of that cell.

If you put =row() in A37, you get 37 back.

=row()-1 is the row number - 1.

Since you wanted to start with 000 (in 000002), and you wanted to start in A1,
the formula had to subtract 1 to get to 0.

Lillian wrote:

Dave:

This work on both, thanks a lots. what is ROW()-1 means?

Lillian

"Dave Peterson" wrote:

Do you really need a macro:

Put something like this in A1 and copy down:

=TEXT((ROW()-1)*2,"000")&"002"

As a macro:

Option Explicit
Sub testme()
With ActiveSheet.Range("a1:a500")
.NumberFormat = "General"
.Formula = "=TEXT((ROW()-1)*2,""000"")&""002"""
.NumberFormat = "@"
.Value = .Value
End With
End Sub

Lillian wrote:

I have one excel spreed sheet on columnA one row A1 has "000002", on the 3rd
charactor I need to change to 2 for second row as "002002", then third row
will be as "004002", I need to increment 2 from the previous row until to the
end of row as"998002", how to run with the macro.
000002
002002
004002
006002
..........
998002

Thank you so much.


--

Dave Peterson


--

Dave Peterson
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
Creating a conditional formula to increment #s in a test script Derek Megyesi Excel Discussion (Misc queries) 0 March 16th 10 08:27 PM
Auto Increment Number Thomas [PBD] Excel Discussion (Misc queries) 0 June 24th 08 10:01 PM
increment version number Lozza77 Excel Discussion (Misc queries) 4 May 17th 06 09:17 AM
How do I Increment a particular woksheet number? [email protected] Excel Worksheet Functions 2 March 6th 06 02:36 AM
Increment number by 1 Joe Derr Excel Programming 5 May 16th 04 08:28 PM


All times are GMT +1. The time now is 04:18 PM.

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"