Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Calculate value based on a cell and inputbox

Hello all,

I have a quoting sheet and I want to be able to prorate # of months an item
will be covered by warranty based on a date. What I have is 30 lines so I
would want an inputbox to open if the user inserts a Y in the "C" Column. The
inputbox would ask for a date and it would take that date and subtract it
from a cell that has a different date in it. Thus giving me an answer. I'm
sure this possible, just don't know the proper syntax. I was going to start
of with something like:


Private Sub Worksheet_Changes(ByVal Target As Range)
Dim ans As String
If Target.Address = Range("$C$25", "$C$54") And Target.Value = "Y" Then
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate months",
Sheets("Agreement").ActiveCell.Value)
-then the "ans" would be subtracted from cell $L$11-

Can this be done?

P.S. I already have a Private Sub Worksheet_Change(ByVal Target As Range)
being used for a different function, can I add another one to avoid conflict
by adding an "s" to the end to make it Private Sub Worksheet_Changes(ByVal
Target As Range)?

Thanks.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Calculate value based on a cell and inputbox

Brad,
You cannot add an 's' to Worksheet_Change so you must put both
(or more) sets of logic in the one routine. The code below gives an outline
solution.

I changed the the inputbox range reference (to $a$1 for testing) as your
original reference to Activecell does (did) not work. [Your active cell is
Target].

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ans As String, DteDiff As Integer

If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allow for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = Range("$L$11") - DateValue(ans)
MsgBox DteDiff
End With
End If
Else
If Target.Address = "$B$1" Then ' your original logic goes here .....
MsgBox " Add logic here.."
End If

End If
End Sub


HTH

"Brad" wrote:

Hello all,

I have a quoting sheet and I want to be able to prorate # of months an item
will be covered by warranty based on a date. What I have is 30 lines so I
would want an inputbox to open if the user inserts a Y in the "C" Column. The
inputbox would ask for a date and it would take that date and subtract it
from a cell that has a different date in it. Thus giving me an answer. I'm
sure this possible, just don't know the proper syntax. I was going to start
of with something like:


Private Sub Worksheet_Changes(ByVal Target As Range)
Dim ans As String
If Target.Address = Range("$C$25", "$C$54") And Target.Value = "Y" Then
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate months",
Sheets("Agreement").ActiveCell.Value)
-then the "ans" would be subtracted from cell $L$11-

Can this be done?

P.S. I already have a Private Sub Worksheet_Change(ByVal Target As Range)
being used for a different function, can I add another one to avoid conflict
by adding an "s" to the end to make it Private Sub Worksheet_Changes(ByVal
Target As Range)?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Calculate value based on a cell and inputbox

What if I change where the user enters "Y", to say the "B" column. How can I
then have the "Ans" from the input box entered into the "C" column? Would an
offset be possible?


"Toppers" wrote:

Brad,
You cannot add an 's' to Worksheet_Change so you must put both
(or more) sets of logic in the one routine. The code below gives an outline
solution.

I changed the the inputbox range reference (to $a$1 for testing) as your
original reference to Activecell does (did) not work. [Your active cell is
Target].

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ans As String, DteDiff As Integer

If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allow for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = Range("$L$11") - DateValue(ans)
MsgBox DteDiff
End With
End If
Else
If Target.Address = "$B$1" Then ' your original logic goes here .....
MsgBox " Add logic here.."
End If

End If
End Sub


HTH

"Brad" wrote:

Hello all,

I have a quoting sheet and I want to be able to prorate # of months an item
will be covered by warranty based on a date. What I have is 30 lines so I
would want an inputbox to open if the user inserts a Y in the "C" Column. The
inputbox would ask for a date and it would take that date and subtract it
from a cell that has a different date in it. Thus giving me an answer. I'm
sure this possible, just don't know the proper syntax. I was going to start
of with something like:


Private Sub Worksheet_Changes(ByVal Target As Range)
Dim ans As String
If Target.Address = Range("$C$25", "$C$54") And Target.Value = "Y" Then
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate months",
Sheets("Agreement").ActiveCell.Value)
-then the "ans" would be subtracted from cell $L$11-

Can this be done?

P.S. I already have a Private Sub Worksheet_Change(ByVal Target As Range)
being used for a different function, can I add another one to avoid conflict
by adding an "s" to the end to make it Private Sub Worksheet_Changes(ByVal
Target As Range)?

Thanks.



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
Trying to calculate results in one cell, based on data of another ADC76 Excel Discussion (Misc queries) 12 May 9th 09 01:10 AM
Calculate Value on new cell based on List Ranjit S Hans New Users to Excel 5 January 29th 09 01:01 AM
Calculate the number of weeksdays based on a cell value [email protected] Excel Worksheet Functions 10 January 8th 09 05:18 PM
IF statement to calculate based on cell values Jos Excel Worksheet Functions 7 January 30th 07 03:38 PM
Calculate value based on a cell and inputbox Brad Excel Programming 0 April 14th 05 09:24 PM


All times are GMT +1. The time now is 09:47 PM.

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"