Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Reducing A Number By 1 (one)

I have a cell range named CNT. Initially a number is manually entered in CNT
for the number of rows to be added at the cursor's position. Let's say that
number is 2 (two). As the machine adds rows, I want it to decrease the value
of CNT by 1 (one) until the value of CNT equals zero (0). I do not know how
to write an Excel macro line to do this. If it were a Lotus 1-2-3 macro,
that line would be, {let cnt;cnt-1}. My macro's end result is a circular
reference and the value of CNT is 0 (zero) after its first itineration.
Below is my macro.

Sub Macro1()
' Inserts rows until CNT value equals zero
Do Until Range ("CNT") = 0
If Range ("CNT") = 1 Then
ActiveCell.Select
Selection.EntireRow.Insert
Range ("CNT").Formula ="=(CNT)-1" '<-- My incorrect line
End If
Loop
End Sub

Thank you very much for your help.
--
Rodney Getschman
Wisconsin VFW
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Reducing A Number By 1 (one)

Hello William
That's a really neat way of "doing the thing". But, your macro inserts one
row too many. Would you please rewrite it for me to only insert the number
of rows commensurate with the number entered in the cell named CNT? Thanks
again.


"William" wrote:

Hi Chief

Try it this way - the code inserts "x" number of rows from the active cell
where "x" is the number entered in range "CNT". I hope I've interpreted you
post accurately.

Sub test()
Range(ActiveCell, ActiveCell.Offset(Range("CNT"), 0)). _
EntireRow.Insert Shift:=xlDown
End Sub

--
XL2002
Regards

William



"Chief" wrote in message
...
| I have a cell range named CNT. Initially a number is manually entered in
CNT
| for the number of rows to be added at the cursor's position. Let's say
that
| number is 2 (two). As the machine adds rows, I want it to decrease the
value
| of CNT by 1 (one) until the value of CNT equals zero (0). I do not know
how
| to write an Excel macro line to do this. If it were a Lotus 1-2-3 macro,
| that line would be, {let cnt;cnt-1}. My macro's end result is a circular
| reference and the value of CNT is 0 (zero) after its first itineration.
| Below is my macro.
|
| Sub Macro1()
| ' Inserts rows until CNT value equals zero
| Do Until Range ("CNT") = 0
| If Range ("CNT") = 1 Then
| ActiveCell.Select
| Selection.EntireRow.Insert
| Range ("CNT").Formula ="=(CNT)-1" '<-- My incorrect line
| End If
| Loop
| End Sub
|
| Thank you very much for your help.
| --
| Rodney Getschman
| Wisconsin VFW



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Reducing A Number By 1 (one)

Hi Chief

Sub test()
Range(ActiveCell, ActiveCell.Offset(Range("CNT") - 1, 0)). _
EntireRow.Insert Shift:=xlDown
End Sub

--
XL2002
Regards

William



"Chief" wrote in message
...
| Hello William
| That's a really neat way of "doing the thing". But, your macro inserts
one
| row too many. Would you please rewrite it for me to only insert the
number
| of rows commensurate with the number entered in the cell named CNT?
Thanks
| again.
|
|
| "William" wrote:
|
| Hi Chief
|
| Try it this way - the code inserts "x" number of rows from the active
cell
| where "x" is the number entered in range "CNT". I hope I've interpreted
you
| post accurately.
|
| Sub test()
| Range(ActiveCell, ActiveCell.Offset(Range("CNT"), 0)). _
| EntireRow.Insert Shift:=xlDown
| End Sub
|
| --
| XL2002
| Regards
|
| William
|
|

|
| "Chief" wrote in message
| ...
| | I have a cell range named CNT. Initially a number is manually entered
in
| CNT
| | for the number of rows to be added at the cursor's position. Let's
say
| that
| | number is 2 (two). As the machine adds rows, I want it to decrease
the
| value
| | of CNT by 1 (one) until the value of CNT equals zero (0). I do not
know
| how
| | to write an Excel macro line to do this. If it were a Lotus 1-2-3
macro,
| | that line would be, {let cnt;cnt-1}. My macro's end result is a
circular
| | reference and the value of CNT is 0 (zero) after its first
itineration.
| | Below is my macro.
| |
| | Sub Macro1()
| | ' Inserts rows until CNT value equals zero
| | Do Until Range ("CNT") = 0
| | If Range ("CNT") = 1 Then
| | ActiveCell.Select
| | Selection.EntireRow.Insert
| | Range ("CNT").Formula ="=(CNT)-1" '<-- My incorrect line
| | End If
| | Loop
| | End Sub
| |
| | Thank you very much for your help.
| | --
| | Rodney Getschman
| | Wisconsin VFW
|
|
|


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Reducing A Number By 1 (one)

Just another way by putting EntireRow first. Inserting an entire row
assumes "xlDown."

ActiveCell.EntireRow.Resize([CNT]).Insert
'or
ActiveCell.EntireRow.Resize([CNT] - 1).Insert

HTH
Dana DeLouis


"Chief" wrote in message
...
Hello William
That's a really neat way of "doing the thing". But, your macro inserts

one
row too many. Would you please rewrite it for me to only insert the

number
of rows commensurate with the number entered in the cell named CNT?

Thanks
again.


"William" wrote:

Hi Chief

Try it this way - the code inserts "x" number of rows from the active

cell
where "x" is the number entered in range "CNT". I hope I've interpreted

you
post accurately.

Sub test()
Range(ActiveCell, ActiveCell.Offset(Range("CNT"), 0)). _
EntireRow.Insert Shift:=xlDown
End Sub

--
XL2002
Regards

William



"Chief" wrote in message
...
| I have a cell range named CNT. Initially a number is manually entered

in
CNT
| for the number of rows to be added at the cursor's position. Let's

say
that
| number is 2 (two). As the machine adds rows, I want it to decrease

the
value
| of CNT by 1 (one) until the value of CNT equals zero (0). I do not

know
how
| to write an Excel macro line to do this. If it were a Lotus 1-2-3

macro,
| that line would be, {let cnt;cnt-1}. My macro's end result is a

circular
| reference and the value of CNT is 0 (zero) after its first

itineration.
| Below is my macro.
|
| Sub Macro1()
| ' Inserts rows until CNT value equals zero
| Do Until Range ("CNT") = 0
| If Range ("CNT") = 1 Then
| ActiveCell.Select
| Selection.EntireRow.Insert
| Range ("CNT").Formula ="=(CNT)-1" '<-- My incorrect line
| End If
| Loop
| End Sub
|
| Thank you very much for your help.
| --
| Rodney Getschman
| Wisconsin VFW







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
Reducing the number of digits in a cell Borge14 Excel Discussion (Misc queries) 6 August 10th 06 04:31 PM
reducing the number of times an IF statement needs to be calculated in embedded IF statements Harold Good Excel Discussion (Misc queries) 4 November 17th 05 06:36 PM
A reducing number by given dates jdmagoo Excel Discussion (Misc queries) 2 October 5th 05 05:28 PM
A reducing number by given dates jdmagoo New Users to Excel 1 October 5th 05 08:02 AM
how do i create a reducing number that reduces at certain dates jdmagoo Excel Discussion (Misc queries) 1 October 5th 05 07:57 AM


All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"