Question about intervals and results

S

Steve

Hey, I'm having these (hopefully simple problems) with writing in page numbers:
(I also posted this in the newbie section, but maybe it fits better here?)

1. I want to write ex. 7-19 in a cell -
Then in another cell I want excel to give the result of the interval of,
here 12.

2. Now, if that's possible, I also want to ask this:
In one cell i want to write 2 or more different interval, ex
7-19, 81-90.

Can I make excel understand what I'm writing somehow? And get the result of
these intervals in another cell, here 21 (12+9)

Any help will be extremely appreciated - thanks in advance, steve.
 
T

Tom Ogilvy

Range("A1").Value = "'7-19"
Range("A2").Value = "'7-19,81-90"
Range("B1:B2").Formula = "=-Sum(" & Range("A1").Text & ")"
 
S

sebastienm

Hi,
You could use the user-defined worksheet function bellow.
One thing i have changed in your requirement is the page counting. You say
7-19 should return 12, but shouldn't it return 13? Eg: 3-4 would return 2 and
not 1.

'--------------------------------------------------------------
Public Function PInterval(S As String) As Double
Dim v, v1

v = Split(S, ",")
For Each v1 In v
PInterval = PInterval + CDbl(Evaluate("-(" & v1 & ")+1"))
Next
End Function
'-----------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top