Rounding and Solver constraint

A

AllanJ

Is it possible to add a constraint that will round the Changed cell to the nearest 5?
Thanks
AJ
 
J

Juan Sanchez

AJ

you can use code, something like this:

'===================================================
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng, cl
Set rng = [a:b] 'change with the desired range to be
affected
If Intersect(Target, rng) Is Nothing Then Exit Sub
For Each cl In Target
If cl.Value <> "" Then
cl.Value = Application.WorksheetFunction.Ceiling
(cl.Value, 5)
End If
Next cl
End Sub
'===================================================

This should be pasted in the View Code area of the sheet
where you want the constraint...right click on the sheet
tan, select view code and paste the code above in the
white area.

the code will change any cell that changed on columns a
and b, it will replace the value to the next 5 up.

to change the range change the part where it says:

set rng = [a:b] <--- change that as needed...

Cheers
Juan
 
T

Tushar Mehta

Make the 'by changing cell' an integer and then in another cell enter
the formula ={by changing cell} * 5

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
T

Tushar Mehta

Have you tested this with Solver?

AFAIK, Solver fails when anything other than it is responsible for a
change to the worksheet.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

AJ

you can use code, something like this:

'===================================================
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng, cl
Set rng = [a:b] 'change with the desired range to be
affected
If Intersect(Target, rng) Is Nothing Then Exit Sub
For Each cl In Target
If cl.Value <> "" Then
cl.Value = Application.WorksheetFunction.Ceiling
(cl.Value, 5)
End If
Next cl
End Sub
'===================================================

This should be pasted in the View Code area of the sheet
where you want the constraint...right click on the sheet
tan, select view code and paste the code above in the
white area.

the code will change any cell that changed on columns a
and b, it will replace the value to the next 5 up.

to change the range change the part where it says:

set rng = [a:b] <--- change that as needed...

Cheers
Juan
-----Original Message-----
Is it possible to add a constraint that will round the Changed cell to the nearest 5?
Thanks
AJ
.
 

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