当只有一个单元被选中时,每个都失败

时间:2015-05-14 07:35:26

标签: excel vba excel-vba

我在VBA中选择一个变体范围

Dim source as variant
source = Range("A4:A" & rowcount)

然后我每个人都有一个

For Each element in source 
.....
.....

当选择了2-3个值时,此功能有效,但当rowcount为4时,Range("A4:A" & rowcount)将仅选择一个单元格而且每个单元格都不起作用

即使只有一个值,我怎样才能使它工作

我试过

If (rowcount=4) Then
    redim preserve source(1)
    source(1,1) = source

但它不起作用

2 个答案:

答案 0 :(得分:1)

您需要将其设为2维

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

int main(int argc, char ** argv) {
  int fd;
  // Open the Port. We want read/write, no "controlling tty" status, and open i$
  fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open /dev/ttyAMA0 - ");
    return(-1);
  }

  // Turn off blocking for reads, use (fd, F_SETFL, FNDELAY) if you want that
  fcntl(fd, F_SETFL, 0);

// Write to the port
  int n = write(fd,"11111 1 1",10);
  if (n < 0) {
    perror("Write failed - ");
    return -1;
  }

  // Don't forget to clean up
  close(fd);
  return 0;
}

答案 1 :(得分:0)

试试这个,看看这是否适合你:

其中,ThisWorkbook.Sheets(1)引用工作簿的Sheet1。

Sub try()
Dim source As Range
RowCount = 4
Set source = ThisWorkbook.Sheets(1).Range("A4:A" & RowCount)

For Each element In source
MsgBox "hi"

Next

End Sub