为什么控制直接进入“End Sub”?

时间:2015-10-05 09:27:41

标签: excel vba excel-vba

我使用了一个名为rng的变量作为Range。 我通过使用找到了最后一行:

lastrow = tmpSheet.Cells(tmpSheet.Rows.Count, "A").End(xlUp).Row

&安培;在使用以下方法找到Foundcell(范围格式)中的单词后

Set Foundcell = tmpSheet.Range("A2:A" & lastrow).Find(What:="ABC")

Do Until Foundcell Is Nothing
      Set rng = tmpSheet.Range(Cells(1, 1), Cells(lastrow, 1))
       .
       .
        (Copy the row from a aheet to another)
       .
       .
errHandler:


End Sub

在获得Foundcell中的值后,控件直接从“Set rng”行转到End Sub。我没有得到它为什么会发生?

2 个答案:

答案 0 :(得分:2)

如果要在tmpsheet上获得单元格(1,1)到单元格(lastrow,1),则应将Set Rng行更改为:

-(void)setquestions:(int)qid
{
    NSManagedObject *singleobject = nil;
    singleobject = AllQuestions[qid];

    NSString * desc=[singleobject valueForKey:@"questionDesc"];
    questionlabel.text=desc;

    int qidns=[[singleobject valueForKey:@"questionId"]intValue];

    NSArray *dummy=[self getoptions:qidns];

    NSLog(@"--inside setquestion-%lu",(unsigned long)dummy.count);

    for (int i=0; i<dummy.count; i++) {
        NSManagedObject *singleobject = nil;
        singleobject = dummy[i];
        NSString * desc=[singleobject valueForKey:@"optionDesc"];
        [self addbutton:desc bid:i];
    }
}

-(void)addbutton:(NSString *)desc bid:(int)bid{
    [[QBFlatButton appearance] setFaceColor:[UIColor colorWithWhite:0.75 alpha:1.0] forState:UIControlStateNormal];
    [[QBFlatButton appearance] setSideColor:[UIColor colorWithWhite:0.55 alpha:1.0] forState:UIControlStateNormal];

    optionButton = [QBFlatButton buttonWithType:UIButtonTypeCustom];
    optionButton.faceColor = [UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f];
    optionButton.sideColor = [UIColor colorWithRed:0.400f green:0.737f blue:0.761f alpha:1.00f];
    optionButton.radius = 4.0;
    optionButton.margin = 4.0;
    optionButton.depth = 3.0;
    [optionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    optionButton.titleLabel.font=[UIFont systemFontOfSize:12];
    optionButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
    // you probably want to center it
    optionButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    optionButton.tag=bid;
    [optionButton setTitle:desc forState:UIControlStateNormal];
    optionButton.frame = CGRectMake(5,bid*55,optionsview.frame.size.width-10, 50);
    [optionsview addSubview:optionButton];
}

- (void)logItems {
    int index = 0;
    for ( NSString *str in self.items ) {
        NSLog(@"%d: %@", index++, str);
    }
}

#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.items count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];

    if ( cell == nil ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    return cell;
}
#pragma mark - Edit Mode
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone; // No Delete icon
}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

    [table deselectRowAtIndexPath:indexPath animated:YES];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Can move cell
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {

    NSUInteger origins = sourceIndexPath.row;  // Original position
    NSUInteger to = destinationIndexPath.row; // Destination position
    NSLog(@"Origin %lu, To %lu", (unsigned long)origins, (unsigned long)to);
    NSString *swap = [self.items objectAtIndex:origin];// Item
    [swap shouldGroupAccessibilityChildren];
}

代替。

答案 1 :(得分:0)

您没有提供整个代码,但这可能正是您所寻找的。

Sub Button1_Click()
    Dim tmpSheet As Worksheet
    Dim PasteSH As Worksheet
    Dim lastrow As Long
    Dim rng As Range
    Dim c As Range

    Set tmpSheet = Sheets("Sheet1")
    Set PasteSH = Sheets("Sheet2")

    With tmpSheet
        lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set rng = .Range("A2:A" & lastrow)
    End With

    For Each c In rng.Cells
        If c = "ABC" Then
            c.EntireRow.Copy PasteSH.Cells(PasteSH.Rows.Count, "A").End(xlUp).Offset(1)
        End If
    Next c

End Sub