B
Ben Allen
I have a peice of code which adds data to a spreadshet via a form and then
runs a solver command, however, the solver code only runs for row 4 at the
moment. How can i make it so that the row in which data has just been copied
is the one in which the solver runs?
Thanks for any help.
'Add Button
Private Sub Add_Click()
'Data Validation
ActiveWorkbook.Sheets("Bookings").Activate
ActiveSheet.Unprotect
Range("b4").Select
Do
'First Empty Cell
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
'Copy Data
ActiveCell.Value = tourref.Value
ActiveCell.Offset(0, -1) = DateText.Value
ActiveCell.Offset(0, 1) = CountryText.Value
ActiveCell.Offset(0, 2) = PlaceText.Value
ActiveCell.Offset(0, 3) = AdultsText.Value
ActiveCell.Offset(0, 4) = ChildrenText.Value
ActiveCell.Offset(0, 5) = CoachesText.Value
ActiveCell.Offset(0, 6) = MinibusesText.Value
ActiveCell.Offset(0, 7) = TourbusesText.Value
'Solver
SolverOk SetCell:="$K$4", MaxMinVal:=2, ValueOf:="0",
ByChange:="$H$4:$J$4"
SolverAdd CellRef:="$H$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$I$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$J$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$H$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$I$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$J$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$L$4", Relation:=3, FormulaText:="$F$4+$G$4"""
SolverSolve
Range("b4").Select
End Sub
--
Cheers,
Ben
Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
runs a solver command, however, the solver code only runs for row 4 at the
moment. How can i make it so that the row in which data has just been copied
is the one in which the solver runs?
Thanks for any help.
'Add Button
Private Sub Add_Click()
'Data Validation
ActiveWorkbook.Sheets("Bookings").Activate
ActiveSheet.Unprotect
Range("b4").Select
Do
'First Empty Cell
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
'Copy Data
ActiveCell.Value = tourref.Value
ActiveCell.Offset(0, -1) = DateText.Value
ActiveCell.Offset(0, 1) = CountryText.Value
ActiveCell.Offset(0, 2) = PlaceText.Value
ActiveCell.Offset(0, 3) = AdultsText.Value
ActiveCell.Offset(0, 4) = ChildrenText.Value
ActiveCell.Offset(0, 5) = CoachesText.Value
ActiveCell.Offset(0, 6) = MinibusesText.Value
ActiveCell.Offset(0, 7) = TourbusesText.Value
'Solver
SolverOk SetCell:="$K$4", MaxMinVal:=2, ValueOf:="0",
ByChange:="$H$4:$J$4"
SolverAdd CellRef:="$H$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$I$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$J$4", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$H$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$I$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$J$4", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$L$4", Relation:=3, FormulaText:="$F$4+$G$4"""
SolverSolve
Range("b4").Select
End Sub
--
Cheers,
Ben
Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"