(VBA)尝试制作具有4行n列的数组

时间:2019-02-27 03:11:10

标签: arrays excel vba

Sub abcd()

Dim numcomps As Integer
numcomps = Range("B3").Value
Dim constants() As Integer
ReDim constants(1 To 4, 1 To numcomps)
Dim i As Integer, j As Integer, k As Integer, compnum As Integer

For k = 1 To numcomps
compnum = Cells(k, 7).Value
   For i = 1 To 4
   constants(i, k) = Cells((compnum + 6), (i + 2)).Value

   Next i
Next k

MsgBox (constants(1, 1))
MsgBox (constants(2, 1))
MsgBox (constants(3, 1))


End Sub

基本上,我正在尝试制作一个包含4行和n列的数组,其中n由用户指定为numcomps。每列将包含从电子表格中的一个表格中收集的4个常量。每次循环时,该代码似乎都在重写数组中的值,而不是创建新列。我需要添加/更改什么?

1 个答案:

答案 0 :(得分:0)

尝试此自定义从何处开始收集数据

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo parallax effect</title>
<style>
body {
   margin: 0 !important;
} 
.parallax {
  /* The image used */
  background-image: url("macbook.jpeg");
  /* Set a specific height */
  min-height: 410px; 
  /*  max-width: 100%; */

  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: top;
  background-repeat: no-repeat;
  background-size: cover;
  padding: 0px;
}
</style>
</head>
<body>
<div class="parallax"></div>
<div style="height:1000px;background-color: aliceblue;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</body>
</html>