|
因代码过大,无法执行。
1、总行数70行,涉及3列
2、行数变动,列固定
哪位大师看编写代码,指导我一下,能够用for或其他语句循环,达到效果。谢谢
Sub 利趋结构比()
Dim pf2
Set pf2 = Sheets("利趋分析") '定义对象,方便后面使用
'根据题意进行赋值
pf2.Cells(8, 5) = "100%"
pf2.Cells(8, 6) = "100%"
pf2.Cells(8, 7) = "0.00%"
If pf2.Cells(8, 3) = "—" And pf2.Cells(9, 3) = "—" Then
pf2.Cells(9, 5) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(9, 3) <> "—" Then
pf2.Cells(9, 5) = Round(pf2.Cells(9, 3) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(9, 3) = "—" Then
pf2.Cells(9, 5) = "—"
Else
pf2.Cells(9, 5) = Round(pf2.Cells(9, 3) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(8, 3) = "—" And pf2.Cells(9, 4) = "—" Then
pf2.Cells(9, 6) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(9, 4) <> "—" Then
pf2.Cells(9, 6) = Round(pf2.Cells(9, 4) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(9, 4) = "—" Then
pf2.Cells(9, 6) = "—"
Else
pf2.Cells(9, 6) = Round(pf2.Cells(9, 4) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(9, 5) = "—" And pf2.Cells(9, 6) = "—" Then
pf2.Cells(9, 7) = "—"
ElseIf pf2.Cells(9, 5) = "—" And pf2.Cells(9, 6) <> "—" Then
pf2.Cells(9, 7) = pf2.Cells(9, 6)
ElseIf pf2.Cells(9, 5) <> "—" And pf2.Cells(9, 6) = "—" Then
pf2.Cells(9, 7) = -pf2.Cells(9, 5)
ElseIf pf2.Cells(9, 5) <> "—" And pf2.Cells(9, 6) <> "—" Then
pf2.Cells(9, 7) = Round(pf2.Cells(9, 6) - pf2.Cells(9, 5), 2)
pf2.Cells(9, 7).Value = pf2.Cells(9, 7).Value
End If
If pf2.Cells(8, 3) = "—" And pf2.Cells(10, 3) = "—" Then
pf2.Cells(10, 5) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(10, 3) <> "—" Then
pf2.Cells(10, 5) = Round(pf2.Cells(10, 3) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(10, 3) = "—" Then
pf2.Cells(10, 5) = "—"
Else
pf2.Cells(10, 5) = Round(pf2.Cells(10, 3) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(8, 3) = "—" And pf2.Cells(10, 4) = "—" Then
pf2.Cells(10, 6) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(10, 4) <> "—" Then
pf2.Cells(10, 6) = Round(pf2.Cells(10, 4) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(10, 4) = "—" Then
pf2.Cells(10, 6) = "—"
Else
pf2.Cells(10, 6) = Round(pf2.Cells(10, 4) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(10, 5) = "—" And pf2.Cells(10, 6) = "—" Then
pf2.Cells(10, 7) = "—"
ElseIf pf2.Cells(10, 5) = "—" And pf2.Cells(10, 6) <> "—" Then
pf2.Cells(10, 7) = pf2.Cells(10, 6)
ElseIf pf2.Cells(10, 5) <> "—" And pf2.Cells(10, 6) = "—" Then
pf2.Cells(10, 7) = -pf2.Cells(10, 5)
ElseIf pf2.Cells(10, 5) <> "—" And pf2.Cells(10, 6) <> "—" Then
pf2.Cells(10, 7) = Round(pf2.Cells(10, 6) - pf2.Cells(10, 5), 2)
pf2.Cells(10, 7).Value = pf2.Cells(10, 7).Value
End If
If pf2.Cells(8, 3) = "—" And pf2.Cells(11, 3) = "—" Then
pf2.Cells(11, 5) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(11, 3) <> "—" Then
pf2.Cells(11, 5) = Round(pf2.Cells(11, 3) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(11, 3) = "—" Then
pf2.Cells(11, 5) = "—"
Else
pf2.Cells(11, 5) = Round(pf2.Cells(11, 3) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(8, 3) = "—" And pf2.Cells(11, 4) = "—" Then
pf2.Cells(11, 6) = "—"
ElseIf pf2.Cells(8, 3) = "—" And pf2.Cells(11, 4) <> "—" Then
pf2.Cells(11, 6) = Round(pf2.Cells(11, 4) / 1, 2)
ElseIf pf2.Cells(8, 3) <> "—" And pf2.Cells(11, 4) = "—" Then
pf2.Cells(11, 6) = "—"
Else
pf2.Cells(11, 6) = Round(pf2.Cells(11, 4) / pf2.Cells(8, 3), 2)
End If
If pf2.Cells(11, 5) = "—" And pf2.Cells(11, 6) = "—" Then
pf2.Cells(11, 7) = "—"
ElseIf pf2.Cells(11, 5) = "—" And pf2.Cells(11, 6) <> "—" Then
pf2.Cells(11, 7) = pf2.Cells(11, 6)
ElseIf pf2.Cells(11, 5) <> "—" And pf2.Cells(11, 6) = "—" Then
pf2.Cells(11, 7) = -pf2.Cells(11, 5)
ElseIf pf2.Cells(11, 5) <> "—" And pf2.Cells(11, 6) <> "—" Then
pf2.Cells(11, 7) = Round(pf2.Cells(11, 6) - pf2.Cells(11, 5), 2)
pf2.Cells(11, 7).Value = pf2.Cells(11, 7).Value
End If
|
|