VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,419 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,507 people online right now. Registration is fast and FREE... Join Now!




Distribute Values over variable time

 

Distribute Values over variable time, Excel VBA

Soparklion

27 Jun, 2009 - 06:59 PM
Post #1

New D.I.C Head
*

Joined: 7 Jun, 2009
Posts: 2

UPDATE: I've figured out a way to automate this code so that the only input that I need is the desired column for output. How do I get Excel VBA to accept that?

I have data that has values recorded at varied time points (20-360 minutes) and a drug dose recorded every 8-12 hours. I want to distribute that drug dose over all of the time entries since the last dose. My program's issues:

1. It won't accept DrugDose or Bounded as numerical inputs (Type=1)
2. It won't accept TimeRange of DrugRange as Arrays (Type 64)
3. I want to set bounded as the number of entries in Drug Range as:
Bounded = UBound(DrugRange) but I get an error that it expects an array value, regardless of whether DrugRange is type 8 or 64.

CODE
Sub Distribute()
Dim TimeRange As Range
Dim DrugRange As Range
Dim Bound As Integer, DrugDose As Variant

'Show input box to get range of cells for time
Set TimeRange = Application.InputBox(Prompt:="TimeRange", Title:="Distribute", Type:=8)
'Show input box to specify range of cells for output
Set DrugRange = Application.InputBox(Prompt:="DrugRange", Title:="Distribute", Type:=8)
'Show input box to set drug dose
Set DrugDose = Application.InputBox(Prompt:="DrugDose", Title:="Distribute", Type:=8)
'Show input box to get number of time points for distribution
Set Bounded = Application.InputBox(Prompt:="Bounded", Title:="Distribute", Type:=8)

'I want to determine as the size of the array DrugRange, but it states that it wants an array
'Even if I change the type to 64...
'Bound = UBound(TimeRange)

For k = 1 To Bounded
  'Assign a value to each row of the array, allowing for a variable time range
  DrugRange(k) =  DrugDose * (TimeRange(k + 1) - TimeRange(k))/ (TimeRange(Bounded) - TimeRange(0))
Next

End Sub


This post has been edited by Soparklion: 27 Jun, 2009 - 07:47 PM

User is offlineProfile CardPM
+Quote Post


June7

RE: Distribute Values Over Variable Time

28 Jun, 2009 - 01:45 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 476



Thanked: 37 times
My Contributions
If I read this right you are trying to use UBound on a range of cells. Don't think you can. UBound is an array function. Read the values of the cells into an array and then address the array with UBound. Else set variables to the row and column indexes of last cell to use as limits in loops or use IsEmpty function as condition for ending a loop.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:57PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month