L
Legacy 436997
Guest
Hi
This is my first post. Im trying to set up a macro that uses Solver and I have some code below. I was wondering if someone could take a look to see if Im on the right track.
This is what the macro should be doing:
Numbers will always be present in one or all of the following cells: G18, K18 and O18. When the macro starts it does a calculation on each cell with a number in it and then posts the answer in the cell below it. So as an example, for cell K18 3.00 would produce the answer 0.75 and would be posted in cell K19.
Any input/comments would be appreciated.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("MyInputs")) Is Nothing Then Exit Sub
If Target = 0 Or Target = vbNullString Then Exit Sub
Dim cLet As String
Target.Offset(1, 0).ClearContents
If Target.Value > 0 Then
cLet = Target.Offset(2, 0).Value
Range("I14").Formula = "=I14+INDIRECT(""" & cLet & """&""14"")"
Range("J14").Formula = "=J14/2*INDIRECT(""B""&INDIRECT(""" & cLet & """&""14""))"
' Run Solver
Application.Run ("RunSolver")
'Reset
'Activecell = 0
End If
End Sub
<style type="text/css">p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 10); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>
<style type="text/css">p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 10); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>
This is my first post. Im trying to set up a macro that uses Solver and I have some code below. I was wondering if someone could take a look to see if Im on the right track.
This is what the macro should be doing:
Numbers will always be present in one or all of the following cells: G18, K18 and O18. When the macro starts it does a calculation on each cell with a number in it and then posts the answer in the cell below it. So as an example, for cell K18 3.00 would produce the answer 0.75 and would be posted in cell K19.
Any input/comments would be appreciated.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("MyInputs")) Is Nothing Then Exit Sub
If Target = 0 Or Target = vbNullString Then Exit Sub
Dim cLet As String
Target.Offset(1, 0).ClearContents
If Target.Value > 0 Then
cLet = Target.Offset(2, 0).Value
Range("I14").Formula = "=I14+INDIRECT(""" & cLet & """&""14"")"
Range("J14").Formula = "=J14/2*INDIRECT(""B""&INDIRECT(""" & cLet & """&""14""))"
' Run Solver
Application.Run ("RunSolver")
'Reset
'Activecell = 0
End If
End Sub
Code:
<style type="text/css">p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 10); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>
<style type="text/css">p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 10); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>