首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >细胞增殖打印细胞输出- VBA Excel

细胞增殖打印细胞输出- VBA Excel
EN

Stack Overflow用户
提问于 2014-12-22 17:31:28
回答 1查看 245关注 0票数 1
代码语言:javascript
复制
Sub MVCalc()

On Error Resume Next

Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim rowcount As Integer
Dim result As Long

Verification1:
Set rng1 = Application.Selection
Set rng1 = Application.InputBox("Select Market Prices", "MV Calculator", Type:=8)
If rng1.Columns.Count > 1 Then
MsgBox ("Please select only one column")
Set rng1 = Nothing
GoTo Verification1
End If

Verification2:
Set rng2 = Application.Selection
Set rng2 = Application.InputBox("Select Position/Shares", "MV Calculator", Type:=8)
If rng1.Columns.Count > 1 Then
MsgBox ("Please select only one column")
Set rng2 = Nothing
GoTo Verification2
End If

Verification3:
Set rng3 = Application.Selection
Set rng3 = Application.InputBox("Select output area", "Mv Calculator", Type:=8)
If rng3.Columns.Count > 1 Then
MsgBox ("Please select only one column")
Set rng3 = Nothing
GoTo Verification3
End If


If rng1.Rows.Count < rng2.Rows.Count Then
MsgBox ("Too many Position/Shares entries, please check again")
Set rng1 = Nothing
Set rng2 = Nothing
Set rng3 = Nothing
GoTo Verification1

ElseIf rng1.Rows.Count > rng2.Rows.Count Then
MsgBox ("Not enough Position/Shares entries, please check again")
Set rng1 = Nothing
Set rng2 = Nothing
Set rng3 = Nothing
GoTo Verification1

ElseIf rng3.Rows.Count <> rng1.Rows.Count Then
MsgBox ("Output range doesn't match the number of Market Value or Price entries, please redo")
Set rng1 = Nothing
Set rng2 = Nothing
Set rng3 = Nothing
GoTo Verification1

End If

rowcount = rng1.Rows.Count
Dim table()
ReDim table(1 To rowcount, 0)

For i = 1 To rowcount
table(i, 0) = Val(rng1.Cells(i, 1)) * Val(rng2.Cells(i, 1))
Next i

Dim rng4 As Range
Set rng4 = rng3(1).Resize(1, rowcount)
rng4 = table


End Sub

这就是我现在想要的,有什么建议吗?我已经更改了您建议的内容,并且仍然得到了水平行中的第一个条目,而不是各种值相乘的列。我不知道什么是问题,不足以补充任何建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-22 17:52:05

结果是一个数字变量。通过循环重置相同变量的值,直到完成为止,然后将此单个值分配给rng3,该值将进入所选范围的第一个单元格。

在循环之前,设置一个数组并在循环中填充它:

代码语言:javascript
复制
Dim Array()
Redim Array(1 to rowcount,0) ' make it 2-dimentional so you do not need to rotate it later
For i = 1 To rowcount
    Array(i, 0) = Val(rng1.Cells(i, 1)) * Val(rng2.Cells(i, 1))
Next i
' I do not know what rng3 refers to or it's size. We know where it starts.
Dim rngOut as Range
Set rngOut = rng3(1).Resize(1, rowcount) ' a vertical column one-cell wide
rngOut = Array
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27607601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档