Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Updating Code when a row is inserted


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Updating Code when a row is inserted

The best way to accomplish what you want is to use define names on the
worksheet. Go to worksheet menu Insert - Names - Define.

You can define the following cells
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

When rows are deleted the workjsheet will automatically update the define
range and VBA will also be updated.
"ML" wrote:


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")

  #3   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Updating Code when a row is inserted

Hi Joel
Thank you for the help!
I was may aware that I can use named ranges.
I have found that is this specific scenario that I posted; I did not even
need to name a range because it is all formula based, so I simply told C5 to
Sum C127 and so on.
That was an easy fix.

Now, let's suppose I did it the way that you suggested;
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

THat would mean that I would have to give a named range to each cell?
C5 being (abc) and C127 being (xyz) in order for the insert a new row to
work dynaically with my code?

That seems like an awful lot of names to have to create.

There must be a way that when a row is inserted, to tell the macro to
increment +1

I would imaine through a For Each rw loop??

Mark

If there a method





"Joel" wrote:

The best way to accomplish what you want is to use define names on the
worksheet. Go to worksheet menu Insert - Names - Define.

You can define the following cells
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

When rows are deleted the workjsheet will automatically update the define
range and VBA will also be updated.
"ML" wrote:


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Updating Code when a row is inserted

Define cell C127 on worksheet to be SourceData (or similar).

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
For Col = 0 to 4
Range("C5").offset(rowoffset:=0,columnoffset:=Col) .Value = _
Range("SourceData").offset(rowoffset:=0,columnoffs et:=Col)
next col

"ML" wrote:

Hi Joel
Thank you for the help!
I was may aware that I can use named ranges.
I have found that is this specific scenario that I posted; I did not even
need to name a range because it is all formula based, so I simply told C5 to
Sum C127 and so on.
That was an easy fix.

Now, let's suppose I did it the way that you suggested;
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

THat would mean that I would have to give a named range to each cell?
C5 being (abc) and C127 being (xyz) in order for the insert a new row to
work dynaically with my code?

That seems like an awful lot of names to have to create.

There must be a way that when a row is inserted, to tell the macro to
increment +1

I would imaine through a For Each rw loop??

Mark

If there a method





"Joel" wrote:

The best way to accomplish what you want is to use define names on the
worksheet. Go to worksheet menu Insert - Names - Define.

You can define the following cells
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

When rows are deleted the workjsheet will automatically update the define
range and VBA will also be updated.
"ML" wrote:


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")

  #5   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Updating Code when a row is inserted

Ahhh,
We are definetely getting closer to what I am looking for, only I would do
the reverse and use rows instead of columns.Also I don't think we need to use
the full word in the array when doing offsetts

Dim rw as Integer

For rw = 6 to 58
Range("C" & rw).offset.Value = _
Range("C127").offset(rw,0)
next rw

Hummmm, what do you think?

Mark



"Joel" wrote:

Define cell C127 on worksheet to be SourceData (or similar).

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
For Col = 0 to 4
Range("C5").offset(rowoffset:=0,columnoffset:=Col) .Value = _
Range("SourceData").offset(rowoffset:=0,columnoffs et:=Col)
next col

"ML" wrote:

Hi Joel
Thank you for the help!
I was may aware that I can use named ranges.
I have found that is this specific scenario that I posted; I did not even
need to name a range because it is all formula based, so I simply told C5 to
Sum C127 and so on.
That was an easy fix.

Now, let's suppose I did it the way that you suggested;
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

THat would mean that I would have to give a named range to each cell?
C5 being (abc) and C127 being (xyz) in order for the insert a new row to
work dynaically with my code?

That seems like an awful lot of names to have to create.

There must be a way that when a row is inserted, to tell the macro to
increment +1

I would imaine through a For Each rw loop??

Mark

If there a method





"Joel" wrote:

The best way to accomplish what you want is to use define names on the
worksheet. Go to worksheet menu Insert - Names - Define.

You can define the following cells
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

When rows are deleted the workjsheet will automatically update the define
range and VBA will also be updated.
"ML" wrote:


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Updating Code when a row is inserted

You have a number of problems with this code.
1) remove offset from Range("C" & rw).offset.Value
2) subtract 6 from row offset Range("C127").offset(rw - 6,0)
3) It still doesn't solve your real problem. If a new row is inserted
between rows 58 and 127 you are copying an empty row. If you add a define
cell then when the row is inserted the define automatically gets updated.

"ML" wrote:

Ahhh,
We are definetely getting closer to what I am looking for, only I would do
the reverse and use rows instead of columns.Also I don't think we need to use
the full word in the array when doing offsetts

Dim rw as Integer

For rw = 6 to 58
Range("C" & rw).offset.Value = _
Range("C127").offset(rw,0)
next rw

Hummmm, what do you think?

Mark



"Joel" wrote:

Define cell C127 on worksheet to be SourceData (or similar).

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
For Col = 0 to 4
Range("C5").offset(rowoffset:=0,columnoffset:=Col) .Value = _
Range("SourceData").offset(rowoffset:=0,columnoffs et:=Col)
next col

"ML" wrote:

Hi Joel
Thank you for the help!
I was may aware that I can use named ranges.
I have found that is this specific scenario that I posted; I did not even
need to name a range because it is all formula based, so I simply told C5 to
Sum C127 and so on.
That was an easy fix.

Now, let's suppose I did it the way that you suggested;
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

THat would mean that I would have to give a named range to each cell?
C5 being (abc) and C127 being (xyz) in order for the insert a new row to
work dynaically with my code?

That seems like an awful lot of names to have to create.

There must be a way that when a row is inserted, to tell the macro to
increment +1

I would imaine through a For Each rw loop??

Mark

If there a method





"Joel" wrote:

The best way to accomplish what you want is to use define names on the
worksheet. Go to worksheet menu Insert - Names - Define.

You can define the following cells
abc as C5
xyz as C127

Then in VBA
Range("abc") = Range ("xyz")

When rows are deleted the workjsheet will automatically update the define
range and VBA will also be updated.
"ML" wrote:


Hi I have a lot of VBA code in a budget spread sheet.
When a person inserts a row, I need my macros to somehow update dynamically.

One "small" example would be on my calculate worksheet event
If the user inserts a row, at 127 for example, then the value of cell C5 is
lost.
Is there a way to C127 become C128 if a row is inserted?

Thank you,
Mark

Private Sub Worksheet_Calculate()

'Extra Cash Cells in Row 5 = Extra Cash Cells in Row 127
Range("C5").Value = Range("C127")
Range("D5").Value = Range("D127")
Range("E5").Value = Range("E127")
Range("F5").Value = Range("F127")
Range("G5").Value = Range("G127")

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
Updating OLD code SanInTexas Excel Programming 3 August 29th 07 08:09 PM
Updating Excel Code Joel Excel Programming 4 November 8th 06 12:32 PM
Updating VB Code Adam Excel Programming 4 April 25th 05 03:43 PM
Running code after a picture has been inserted? Tom Jones Excel Programming 1 January 18th 05 04:38 PM
inserted code into project but can't run it in run dialogbox cpudenusa Excel Programming 3 July 19th 03 06:24 PM


All times are GMT +1. The time now is 10:17 AM.

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"