以梦为马,不负韶华

搜索
查看: 2029|回复: 1
收起左侧

[原创] 用excel的宏求解精馏塔塔板数,编码错误。求大神指导,我把编好的编码一起打包了。

[复制链接]
发表于 2016-3-20 13:15:36 显示全部楼层 |阅读模式
用excel的宏求解精馏塔塔板数,编码错误。求大神指导,我把编好的编码一起打包了。

用excel的宏求解精馏塔塔板数的编码出现错误,求大神指导.rar

315.93 KB, 下载次数: 33

 成长值: 47950

发表于 2016-3-20 13:15:36 显示全部楼层

回帖奖励 +6 个韶华币

excel文件里为空,确定有代码?

评分

参与人数 1 +2 收起 理由
小招忒 + 2 谢谢帮助

查看全部评分

回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-20 13:15:36 显示全部楼层

不好意思,我第一次用宏。可能我保存的时候方法错了没有了。这是我编的代码                        Sub hong()
Dim xcz(100) As Variant
Dim ycz(100) As Variant
Dim xph(100) As Variant
Dim yph(100) As Variant
Dim u(100) As Variant
Dim v(100) As Variant
For i = 1 To 100
u(i) = ActiveSheet.Cells(i, 6)
v(i) = ActiveSheet.Cells(i, 5)
If u(1) = 1 And u(i) = 0 Then nph = i
If u(1) = 0 And u(i) = 1 Then nph = i
Next i
xa=ActiveSheet.Cells(1£¬15)
ya=ActiveSheet.Cells(1£¬15)
xb=ActiveSheet.Cells(2£¬15)
yb=ActiveSheet.Cells(2£¬15)
q=ActiveSheet.Cells(3£¬15)
R = ActiveSheet.Cells(4, 15)
xf=ActiveSheet.Cells (5£¬15)
xd=((xa/(R+1)+(xf/(q-1 +1e-10)))/((q/(q-1+le-10)Ò»(R/ (R+1))
yd=q/(q-1 +1e-10)*((xa/(R+1)+(xf/(q-1+le-10)))/((q/(q-1+1e-10)
-(R/(R+1))Ò»xf / (q-1+1 e-10)
ActiveSheet.Cells(6, 15) = xd
ActiveSheet.Cells(6, 16) = yd
xc = xa
yc = ya
For i = 1 To 100
xcz(i) = xc
ycz(i) = yc
xc = chazhi(u, v, yc, npl)
xph(i) = xc
yph(i) = yc
ActiveSheet.Cells(i, 1) = xph(i)
ActiveSheet.Cells(i, 2) = yph(i)
ActiveSheet.Cells(i*2-1£¬11)=xcz(i)
    ActiveSheet.Cells(i*2-1£¬12)=ycz(i)
    ActiveSheet.Cells(2 * i, 11) = xph(i)
    ActiveSheet.Cells(2 * i, 12) = yph(i)
    If xc < xd Then
    xab = xb
    yab = yb
    Else
    xab = xa
    yab = ya
    End If
    yc = (yab - yd) / (xab - xd) * (xc - yd)
    If xph(i - 1) > xd And xph(i) < xd Then GoTo ActiveSheet
        Cells(5, 8) = i - 1 + (xph(i - 1) - xd) / (xph(i - 1)) = xph(i)
End If
    ActiveSheet.Cells(4, 8) = i - 1 + (xph(i - 1) - xb) / (xph(i - 1) - xph(i))
     If xc < xb Then
     End If
     Next i
     End Sub
Function chazhi(x, y, u, nph)
n = nph
For k = 1 To n - 1
  If (u - x(l) * (u - x(n))) <= 0 Then GoTo 10
  End If
Next k
If (u - x(l) * (u - x(n))) <= 0 Then k = 1 Else k = n - 1
10 G = (u - x(k) * (u - x(k + 1)))
End If
If k = n - 1 Or k <> 1 And G Then k = k - 1
v = 0
For i = k To k + 2
l = 1
For j = k To k + 2
If i <> j Then l = l * (u - x(j)) / (x(i) - x(j))
Next j
v = v + l * y(i)
Next i
chazhi = v
End Function
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-20 13:15:36 显示全部楼层
Sub hong()
Dim xcz(100) As Variant
Dim ycz(100) As Variant
Dim xph(100) As Variant
Dim yph(100) As Variant
Dim u(100) As Variant
Dim v(100) As Variant
Dim i As Integer
Dim nph As Single
Dim xa As Single
Dim ya As Single
Dim xb As Single
Dim yb As Single
Dim q As Single
Dim R As Integer
Dim xf As Single
Dim xd As Single
For i = 1 To 100
u(i) = ActiveSheet.Cells(i, 6)
v(i) = ActiveSheet.Cells(i, 5)
If u(1) = 1 And u(i) = 0 Then nph = i
If u(1) = 0 And u(i) = 1 Then nph = i
Next i
xa = "ActiveSheet.Cells(1,15)"
ya = "ActiveSheet.Cells(1,15)"
xb = "ActiveSheet.Cells(2,15)"
yb = "ActiveSheet.Cells(2,15)"
q = "ActiveSheet.Cells(3,15)"
R = ActiveSheet.Cells(4, 15)
xf = "ActiveSheet.Cells (5,15)"
xd = ((xa / (R + 1) + (xf / (q - 1 + 0.0000000001))) / (q / (q - 1 + le - 10)) - (R / (R + 1)))
yd = q / (q - 1 + 0.0000000001) * ((xa / (R + 1) + (xf / (q - 1 + le - 10))) / (q / (q - 1 + 0.0000000001))) - (R / (R + 1)) - xf / (q - 1 + 0.0000000001)
ActiveSheet.Cells(6, 15) = xd
ActiveSheet.Cells(6, 16) = yd
xc = xa
yc = ya
For i = 1 To 100
xcz(i) = xc
ycz(i) = yc
xc = chazhi(u, v, yc, npl)
xph(i) = xc
yph(i) = yc
ActiveSheet.Cells(i, 1) = xph(i)
ActiveSheet.Cells(i, 2) = yph(i)
xcz(i) = "ActiveSheet.Cells(i*2-1,11)"
    ycz(i) = "ActiveSheet.Cells(i*2-1,12)"
    ActiveSheet.Cells(2 * i, 11) = xph(i)
    ActiveSheet.Cells(2 * i, 12) = yph(i)
    If xc < xd Then
    xab = xb
    yab = yb
    Else
    xab = xa
    yab = ya
    End If
    yc = (yab - yd) / (xab - xd) * (xc - yd)
    If xph(i - 1) > xd And xph(i) < xd Then GoTo ActiveSheet
        Cells(5, 8) = i - 1 + (xph(i - 1) - xd) / (xph(i - 1)) = xph(i)
End If
    ActiveSheet.Cells(4, 8) = i - 1 + (xph(i - 1) - xb) / (xph(i - 1) - xph(i))
     If xc < xb Then
     End If
     Next i
     End Sub
Function chazhi(x, y, u, nph)
n = nph
For k = 1 To n - 1
  If (u - x(l) * (u - x(n))) <= 0 Then GoTo 10
  End If
Next k
If (u - x(l) * (u - x(n))) <= 0 Then k = 1 Else k = n - 1
10 G = (u - x(k) * (u - x(k + 1)))
End If
If k = n - 1 Or k <> 1 And G Then k = k - 1
v = 0
For i = k To k + 2
l = 1
For j = k To k + 2
If i <> j Then l = l * (u - x(j)) / (x(i) - x(j))
Next j
v = v + l * y(i)
Next i
chazhi = v
End Function

刚刚我在调试了下,好像还有点问题。我不会
回复 支持 反对

使用道具 举报

 成长值: 47950

发表于 2016-3-20 13:15:36 显示全部楼层
改了一下,你看看

Sub hong()
        Dim xcz(100) As Variant
        Dim ycz(100) As Variant
        Dim xph(100) As Variant
        Dim yph(100) As Variant
        Dim u(100) As Variant
        Dim v(100) As Variant
        Dim i As Integer
        Dim nph As Single
        Dim xa As Single
        Dim ya As Single
        Dim xb As Single
        Dim yb As Single
        Dim q As Single
        Dim R As Integer
        Dim xf As Single
        Dim xd As Single
        For i = 1 To 100
                u(i) = ActiveSheet.Cells(i, 6)
                v(i) = ActiveSheet.Cells(i, 5)
                If u(1) = 1 And u(i) = 0 Then nph = i
                If u(1) = 0 And u(i) = 1 Then nph = i
        Next i
        xa = ActiveSheet.Cells(1,15)
        ya = ActiveSheet.Cells(1,15)
        xb = ActiveSheet.Cells(2,15)
        yb = ActiveSheet.Cells(2,15)
        q = ActiveSheet.Cells(3,15)
        R = ActiveSheet.Cells(4, 15)
        xf = ActiveSheet.Cells (5,15)
        xd = ((xa / (R + 1) + (xf / (q - 1 + 0.0000000001))) / (q / (q - 1 + le - 10)) - (R / (R + 1)))
        yd = q / (q - 1 + 0.0000000001) * ((xa / (R + 1) + (xf / (q - 1 + le - 10))) / (q / (q - 1 + 0.0000000001))) - (R / (R + 1)) - xf / (q - 1 + 0.0000000001)
        ActiveSheet.Cells(6, 15) = xd
        ActiveSheet.Cells(6, 16) = yd
        xc = xa
        yc = ya
        For i = 1 To 100
                xcz(i) = xc
                ycz(i) = yc
                xc = chazhi(u, v, yc, npl)
                xph(i) = xc
                yph(i) = yc
                ActiveSheet.Cells(i, 1) = xph(i)
                ActiveSheet.Cells(i, 2) = yph(i)
                xcz(i) = ActiveSheet.Cells(i*2-1,11)
                ycz(i) = ActiveSheet.Cells(i*2-1,12)
                ActiveSheet.Cells(2 * i, 11) = xph(i)
                ActiveSheet.Cells(2 * i, 12) = yph(i)
                If xc < xd Then
                        xab = xb
                        yab = yb
                Else
                        xab = xa
                        yab = ya
                End If
                yc = (yab - yd) / (xab - xd) * (xc - yd)
                If xph(i - 1) > xd And xph(i) < xd Then GoTo ActiveSheet
                        Cells(5, 8) = i - 1 + (xph(i - 1) - xd) / (xph(i - 1)) = xph(i)
                End If
                ActiveSheet.Cells(4, 8) = i - 1 + (xph(i - 1) - xb) / (xph(i - 1) - xph(i))
                If xc < xb Then
                End If
        Next i
End Sub

Function chazhi(x, y, u, nph)
        n = nph
        For k = 1 To n - 1
          If (u - x(l) * (u - x(n))) <= 0 Then GoTo 10
          End If
        Next k
        If (u - x(l) * (u - x(n))) <= 0 Then k = 1 Else k = n - 1
        10:
        G = (u - x(k) * (u - x(k + 1)))
        End If
        If k = n - 1 Or k <> 1 And G Then k = k - 1
        v = 0
        For i = k To k + 2
                l = 1
                For j = k To k + 2
                        If i <> j Then l = l * (u - x(j)) / (x(i) - x(j))
                Next j
                v = v + l * y(i)
        Next i
        chazhi = v
End Function
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-20 13:15:36 显示全部楼层
ps122 发表于 2016-3-21 10:36
改了一下,你看看

Sub hong()

谢谢您!好像还有一点点小问题,我运行的时候它显示未定义标签是啥意思。下面这句Activesheet
If xph(i - 1) > xd And xph(i) < xd Then GoTo ActiveSheet

点评

改成这样 If xph(i - 1) > xd And xph(i) < xd Then ActiveSheet.Cells(5, 8) = i - 1 + (xph(i - 1) - xd) / (xph(i - 1)) = xph(i) End If  详情 回复 发表于 2016-3-22 08:19
回复 支持 反对

使用道具 举报

 成长值: 47950

发表于 2016-3-20 13:15:36 显示全部楼层
小招忒 发表于 2016-3-21 16:20
谢谢您!好像还有一点点小问题,我运行的时候它显示未定义标签是啥意思。下面这句Activesheet
If xph(i  ...

改成这样
If xph(i - 1) > xd And xph(i) < xd Then
        ActiveSheet.Cells(5, 8) = i - 1 + (xph(i - 1) - xd) / (xph(i - 1)) = xph(i)
End If
回复 支持 反对

使用道具 举报

发表于 2016-3-20 13:15:36 显示全部楼层

这个帖子不回对不起自己!我想我是一天也不能离开马后炮化工
[发帖际遇]: BMHG001 捡到一块切糕,卖给了小马,赚了 7 个 韶华币. 幸运榜 / 衰神榜
回复 支持 反对

使用道具 举报

不想打字就选择快捷回复吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|以梦为马,不负韶华

GMT+8, 2025-4-4 23:48

Powered by 以梦为马,不负韶华

© 2024-2099 Meng.Horse

快速回复 返回顶部 返回列表