PC Review


Reply
Thread Tools Rate Thread

Automatically copy formulas to new rows added.

 
 
LCN
Guest
Posts: n/a
 
      1st Dec 2008
How do I get a form (that will be protected) using a macro to add additional
lines to automatically copy the formulas above to the new added lines without
adding another macro?
--
Lynn
 
Reply With Quote
 
 
 
 
Eduardo
Guest
Posts: n/a
 
      1st Dec 2008
Try
Sub test()
Dim InsertionPoint As Range, rg As Range
Dim colToCheck As String
Dim expandBy As Long
Dim wsh As Worksheet
Dim StartRow As Long
Dim ws As Worksheet

'Unprotect sheet
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
ws.Select
ws.Unprotect Password:="Password"
Next ws

Set wsh = ActiveSheet
colToCheck = "A"
expandBy = 25
'Find last currently used row in column colToCheck
Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1,
0).EntireRow
StartRow = InsertionPoint.Row - 1

'Insert rows
Set rg = InsertionPoint.Resize(expandBy)
rg.Insert

Range("C" & StartRow).Resize(1, 2).Copy _
Range("C" & StartRow).Resize(expandBy + 1, 2)

'Protect Sheet
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
ws.Select
ws.Protect Password:="Password"
Next ws


End Sub


"LCN" wrote:

> How do I get a form (that will be protected) using a macro to add additional
> lines to automatically copy the formulas above to the new added lines without
> adding another macro?
> --
> Lynn

 
Reply With Quote
 
Shane Devenshire
Guest
Posts: n/a
 
      1st Dec 2008
Hi,

why don't you show us the code you currently have. And how many lines do
you want to add at any one time, or is it just one line? And are you really
asking how to fill the formulas down but leave the remainder of the lines
unchanged?

For example, if you have protected the spreadhsheet using code and the
userinterfaceonly:=true option and you want to extend the formulas down one
row and these formulas are in columns D:H. Then

Bot = Range("D1").End(xlDown).Row
Range("D" & Bot & ":H" & Bot + 1).FillDown

Might do it.

If this helps, please click the Yes button

Cheers,
Shane Devenshire
"LCN" wrote:

> How do I get a form (that will be protected) using a macro to add additional
> lines to automatically copy the formulas above to the new added lines without
> adding another macro?
> --
> Lynn

 
Reply With Quote
 
LCN
Guest
Posts: n/a
 
      2nd Dec 2008
I couldn't get this to work, is it possible for me to forward you my form for
you to review?
--
Lynn


"Eduardo" wrote:

> Try
> Sub test()
> Dim InsertionPoint As Range, rg As Range
> Dim colToCheck As String
> Dim expandBy As Long
> Dim wsh As Worksheet
> Dim StartRow As Long
> Dim ws As Worksheet
>
> 'Unprotect sheet
> Set MySheets = ActiveWindow.SelectedSheets
> For Each ws In MySheets
> ws.Select
> ws.Unprotect Password:="Password"
> Next ws
>
> Set wsh = ActiveSheet
> colToCheck = "A"
> expandBy = 25
> 'Find last currently used row in column colToCheck
> Set InsertionPoint = wsh.Range(colToCheck & 65536).End(xlUp).Offset(1,
> 0).EntireRow
> StartRow = InsertionPoint.Row - 1
>
> 'Insert rows
> Set rg = InsertionPoint.Resize(expandBy)
> rg.Insert
>
> Range("C" & StartRow).Resize(1, 2).Copy _
> Range("C" & StartRow).Resize(expandBy + 1, 2)
>
> 'Protect Sheet
> Set MySheets = ActiveWindow.SelectedSheets
> For Each ws In MySheets
> ws.Select
> ws.Protect Password:="Password"
> Next ws
>
>
> End Sub
>
>
> "LCN" wrote:
>
> > How do I get a form (that will be protected) using a macro to add additional
> > lines to automatically copy the formulas above to the new added lines without
> > adding another macro?
> > --
> > Lynn

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum formulas do NOT expand when rows added ! Blue Max Microsoft Excel Discussion 5 29th Apr 2008 05:13 PM
Sum formulas do NOT expand when rows added ! Blue Max Microsoft Excel Worksheet Functions 5 29th Apr 2008 05:13 PM
how do I lock formulas, but still allow rows to be added or delet. ericaamousseau Microsoft Excel Worksheet Functions 3 18th Jan 2008 07:10 PM
Macro to automatically add rows and copy formulas =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Misc 0 6th Jun 2007 12:00 AM
Automatically copy formulas/functions to inserted rows. =?Utf-8?B?QmFyYmFyYQ==?= Microsoft Excel Worksheet Functions 7 2nd Feb 2007 11:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 AM.