Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 202
Default Formula in a template

I want to create a template that I can use to import a series of numbers into
a column and then have that number changed to a negative number. I tried
placing a formula in column C that would multiply the number in column B by
-1 and display the result in column C.

However when I used the template to create a document, the formula was not
carried to the new document. Any suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Formula in a template

How about event code to change the numbers as they are entered?

No formulas involved.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column < 1 And _
Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
With Target
.Value = .Value * -1
'.NumberFormat = "0;<0"
Application.EnableEvents = True
End With
End Sub

Open a new workbook. Customize as you wish then place this event code into the
sheet.

Right-click on the the sheet tab and "View Code".

Copy/paste into that sheet module.

Now................FileSave AsFile TypeExcel Template(*.xlt)

Give it a name and store it where you like.

I have no idea why your original template had no formulas unless you did not
save correctly.


Gord Dibben MS Excel MVP



On Mon, 14 May 2007 13:58:03 -0700, Dennis
wrote:

I want to create a template that I can use to import a series of numbers into
a column and then have that number changed to a negative number. I tried
placing a formula in column C that would multiply the number in column B by
-1 and display the result in column C.

However when I used the template to create a document, the formula was not
carried to the new document. Any suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 202
Default Formula in a template

Gord,

It works great but how do I limit the action to a single column?

"Gord Dibben" wrote:

How about event code to change the numbers as they are entered?

No formulas involved.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column < 1 And _
Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
With Target
.Value = .Value * -1
'.NumberFormat = "0;<0"
Application.EnableEvents = True
End With
End Sub

Open a new workbook. Customize as you wish then place this event code into the
sheet.

Right-click on the the sheet tab and "View Code".

Copy/paste into that sheet module.

Now................FileSave AsFile TypeExcel Template(*.xlt)

Give it a name and store it where you like.

I have no idea why your original template had no formulas unless you did not
save correctly.


Gord Dibben MS Excel MVP



On Mon, 14 May 2007 13:58:03 -0700, Dennis
wrote:

I want to create a template that I can use to import a series of numbers into
a column and then have that number changed to a negative number. I tried
placing a formula in column C that would multiply the number in column B by
-1 and display the result in column C.

However when I used the template to create a document, the formula was not
carried to the new document. Any suggestions?




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Formula in a template

One way:


Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then Exit Sub
If IsNumeric(Target.Value) = False Then Exit Sub

Application.EnableEvents = False
With Target
.Value = Abs(.Value) * -1
'.NumberFormat = "0;<0"
End With
Application.EnableEvents = True
End Sub

I rearranged some stuff--for just arbitrary reasons.


Dennis wrote:

Gord,

It works great but how do I limit the action to a single column?

"Gord Dibben" wrote:

How about event code to change the numbers as they are entered?

No formulas involved.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column < 1 And _
Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
With Target
.Value = .Value * -1
'.NumberFormat = "0;<0"
Application.EnableEvents = True
End With
End Sub

Open a new workbook. Customize as you wish then place this event code into the
sheet.

Right-click on the the sheet tab and "View Code".

Copy/paste into that sheet module.

Now................FileSave AsFile TypeExcel Template(*.xlt)

Give it a name and store it where you like.

I have no idea why your original template had no formulas unless you did not
save correctly.


Gord Dibben MS Excel MVP



On Mon, 14 May 2007 13:58:03 -0700, Dennis
wrote:

I want to create a template that I can use to import a series of numbers into
a column and then have that number changed to a negative number. I tried
placing a formula in column C that would multiply the number in column B by
-1 and display the result in column C.

However when I used the template to create a document, the formula was not
carried to the new document. Any suggestions?





--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Formula in a template

Sorry about that Dennis.

Try this construct............change the ("A:A") to your choice.

OR ("A:A, C:C, E:E") for cols A, C and E

OR ("A1:B23") for a range

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit:
Application.EnableEvents = False
For Each rng In vRngInput
If IsNumeric(rng.Value) Then

With rng
.Value = .Value * -1
'.NumberFormat = "0;<0"

End With
End If
Next
endit:
Application.EnableEvents = True
End Sub


Gord

On Mon, 14 May 2007 17:27:00 -0700, Dennis
wrote:

Gord,

It works great but how do I limit the action to a single column?

"Gord Dibben" wrote:

How about event code to change the numbers as they are entered?

No formulas involved.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column < 1 And _
Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
With Target
.Value = .Value * -1
'.NumberFormat = "0;<0"
Application.EnableEvents = True
End With
End Sub

Open a new workbook. Customize as you wish then place this event code into the
sheet.

Right-click on the the sheet tab and "View Code".

Copy/paste into that sheet module.

Now................FileSave AsFile TypeExcel Template(*.xlt)

Give it a name and store it where you like.

I have no idea why your original template had no formulas unless you did not
save correctly.


Gord Dibben MS Excel MVP



On Mon, 14 May 2007 13:58:03 -0700, Dennis
wrote:

I want to create a template that I can use to import a series of numbers into
a column and then have that number changed to a negative number. I tried
placing a formula in column C that would multiply the number in column B by
-1 and display the result in column C.

However when I used the template to create a document, the formula was not
carried to the new document. Any suggestions?







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
What template or formula A Healthy Connection Excel Discussion (Misc queries) 0 April 7th 07 07:52 PM
Database Formula in a Template Sarah About this forum 0 August 22nd 06 02:26 AM
Using today formula for a template Mike Busch Excel Discussion (Misc queries) 3 August 8th 05 01:44 PM
I have problems keeping the merge formula to use as a template. PBrunner Excel Discussion (Misc queries) 2 June 20th 05 10:45 PM
Formula Template Carole O Excel Worksheet Functions 0 March 24th 05 06:59 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"