VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • excel vba教程之两条直线的交点坐标(单变量求解

1.  两条直线的交点坐标(单变量求解、Replace、Iif、Like、Evaluate、绝对引用)by:狼版主

‘直线交点坐标.xls
‘http://club.excelhome.net/dispbbs.asp?boardid=2&id=272572&star=1#1044619
Sub macro1()
Dim q1 As String, q2 As String
q1 = "y=9-2x"
q2 = "y=x-3"
[a2] = Replace(Mid(q1, 2), "x", IIf(q1 Like "*[=+-]x*", "", "*") & "r1c1") & "-(" & Replace(Mid(q2, 3), "x", IIf(q2 Like "*[=+-]x*", "", "*") & "r1c1") & ")"
[a2].GoalSeek 0, [a1]
MsgBox "x=" & [a1] & vbCrLf & "y=" & Evaluate(Replace(Mid(q1, 3), "x", IIf(q1 Like "*[=+-]x*", "", "*") & [a1]))
[a1:a2] = ""
End Sub
 
用IIf(q1 Like "*[=+-]x*", "", "*")来判别q1里面x前面是数字还是=+-号
[a4] = Replace(Mid(q1, 2), "x", IIf(q1 Like "*[=+-]x*", "", "*") & "r1c1")  [a4]单元格里是绝对引用的公式=9-2*$A$1,A1值改变A4值也改变;
[a5] = Replace(Mid(q1, 3), "x", IIf(q1 Like "*[=+-]x*", "", "*") & [a1])    [a5]单元格里是文本,因为没有”=”,9-2*4,引用的是A1的值;
[a6] = Replace(Mid(q1, 2), "x", IIf(q1 Like "*[=+-]x*", "", "*") & [a1])    [a6]单元格里是数值1,公式=9-2*4, A1值改变A4值不改变。

相关教程