Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default % variance calculation

Can anybody help me to correct this macro:


Sub Macro1()

Dim exptype

exptype = InputBox("Enter e if expense type.")

ActiveCell.FormulaR1C1 =
"=IF(exptype=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"

End Sub

Am getting error #NAME?

I do not want to refer exptype to any cell as it's only a general input

Thxs

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default % variance calculation

two ways to fix this

Option Explicit
Sub Macro1()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
ActiveCell.FormulaR1C1 = _
"=IF(""" & exptype & """=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"
End Sub


Sub Macro1_new()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
If UCase(exptype) = "E" Then
ActiveCell.FormulaR1C1 = "=-(RC[-1]/RC[-2]-1)"
Else
ActiveCell.FormulaR1C1 = "=(RC[-1]/RC[-2]-1)"
End If
End Sub

The secnd example is far easier to understand and this debug at some future
date

"al" wrote:

Can anybody help me to correct this macro:


Sub Macro1()

Dim exptype

exptype = InputBox("Enter e if expense type.")

ActiveCell.FormulaR1C1 =
"=IF(exptype=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"

End Sub

Am getting error #NAME?

I do not want to refer exptype to any cell as it's only a general input

Thxs


  #3   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default % variance calculation

Thxs a lot Patrick !!

Patrick Molloy wrote:
two ways to fix this

Option Explicit
Sub Macro1()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
ActiveCell.FormulaR1C1 = _
"=IF(""" & exptype & """=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"
End Sub


Sub Macro1_new()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
If UCase(exptype) = "E" Then
ActiveCell.FormulaR1C1 = "=-(RC[-1]/RC[-2]-1)"
Else
ActiveCell.FormulaR1C1 = "=(RC[-1]/RC[-2]-1)"
End If
End Sub

The secnd example is far easier to understand and this debug at some future
date

"al" wrote:

Can anybody help me to correct this macro:


Sub Macro1()

Dim exptype

exptype = InputBox("Enter e if expense type.")

ActiveCell.FormulaR1C1 =
"=IF(exptype=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"

End Sub

Am getting error #NAME?

I do not want to refer exptype to any cell as it's only a general input

Thxs



  #4   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default % variance calculation

Patrick can you help me with this macro:

Sub Variance1()

Dim exptype

exptype = InputBox("Enter e if expense type, else blank.")

Dim Actual
Actual = InputBox("Select cell for Actual data.")

Dim Std
Std = InputBox("Select cell for Standard data.")



If exptype = "e" Then

ActiveCell.Formula = "=-(Actual/Std-1)"

Else

ActiveCell.Formula = "=Actual/Std-1"

End If
Selection.Style = "Percent"
End Sub

I want Actual & Std to be the cell address of my selected cells
Am new to excel & not familiar with input box, specially cell addresses

Thxs
Al



Patrick Molloy wrote:
two ways to fix this

Option Explicit
Sub Macro1()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
ActiveCell.FormulaR1C1 = _
"=IF(""" & exptype & """=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"
End Sub


Sub Macro1_new()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
If UCase(exptype) = "E" Then
ActiveCell.FormulaR1C1 = "=-(RC[-1]/RC[-2]-1)"
Else
ActiveCell.FormulaR1C1 = "=(RC[-1]/RC[-2]-1)"
End If
End Sub

The secnd example is far easier to understand and this debug at some future
date

"al" wrote:

Can anybody help me to correct this macro:


Sub Macro1()

Dim exptype

exptype = InputBox("Enter e if expense type.")

ActiveCell.FormulaR1C1 =
"=IF(exptype=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"

End Sub

Am getting error #NAME?

I do not want to refer exptype to any cell as it's only a general input

Thxs



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default % variance calculation

you have not expalined the difference between Std and Actual. However, take a
look at this...

Option Explicit

Sub Variance1()

Dim exptype As String
Dim Actual As Range
Dim Std As Range

exptype = InputBox("Enter e if expense type, else blank.")


Set Actual = Application.InputBox("Actual data.", "Select cell for ...",
Type:=8)


Set Std = Application.InputBox("Standard data.", "Select cell for ...",
Type:=8)



If exptype = "e" Then

Actual.Formula = "=-(Actual/Std-1)"

Else

Actual.Formula = "=Actual/Std-1"

End If
Actual.NumberFormat = "0.00%;-0.00%;-"
End Sub



"al" wrote:

Patrick can you help me with this macro:

Sub Variance1()

Dim exptype

exptype = InputBox("Enter e if expense type, else blank.")

Dim Actual
Actual = InputBox("Select cell for Actual data.")

Dim Std
Std = InputBox("Select cell for Standard data.")



If exptype = "e" Then

ActiveCell.Formula = "=-(Actual/Std-1)"

Else

ActiveCell.Formula = "=Actual/Std-1"

End If
Selection.Style = "Percent"
End Sub

I want Actual & Std to be the cell address of my selected cells
Am new to excel & not familiar with input box, specially cell addresses

Thxs
Al



Patrick Molloy wrote:
two ways to fix this

Option Explicit
Sub Macro1()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
ActiveCell.FormulaR1C1 = _
"=IF(""" & exptype & """=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"
End Sub


Sub Macro1_new()
Dim exptype As String
exptype = InputBox("Enter e if expense type.")
If UCase(exptype) = "E" Then
ActiveCell.FormulaR1C1 = "=-(RC[-1]/RC[-2]-1)"
Else
ActiveCell.FormulaR1C1 = "=(RC[-1]/RC[-2]-1)"
End If
End Sub

The secnd example is far easier to understand and this debug at some future
date

"al" wrote:

Can anybody help me to correct this macro:


Sub Macro1()

Dim exptype

exptype = InputBox("Enter e if expense type.")

ActiveCell.FormulaR1C1 =
"=IF(exptype=""e"",-(RC[-1]/RC[-2]-1),RC[-1]/RC[-2]-1)"

End Sub

Am getting error #NAME?

I do not want to refer exptype to any cell as it's only a general input

Thxs




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
Pivot table and variance calculation vivi Excel Discussion (Misc queries) 1 February 1st 10 07:11 PM
variance % karibug Excel Worksheet Functions 5 June 14th 06 10:54 PM
Pivot Tables - Variance and Variance % PJS Excel Discussion (Misc queries) 2 January 18th 06 03:12 AM
Pivot Tables - Variance and % Variance fields CraigS Excel Discussion (Misc queries) 5 January 6th 05 12:22 AM
Variance calculation N.C. Arens Excel Worksheet Functions 1 December 5th 04 07:44 AM


All times are GMT +1. The time now is 04:20 AM.

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"