VBA Two for Loop并将值收集到第二张纸

时间:2016-11-23 08:22:26

标签: excel-vba vba excel

我正在尝试让这个子程序工作。

我有一张表(ws1)中的数据,如果值不是0到表(ws),我将循环并复制数据.Range(" E5")。end(xldown)。偏移(1,0)

请帮忙

 Sub Test()

 Dim r As Integer
 Dim c As Integer
 Dim amount As Long
 Dim account As Variant
 Dim Acct As Range
 Dim Amt As Range
 Dim ws1 As Worksheet
 Dim target As Range
 Dim ws As Worksheet
 Set ws1 = ActiveSheet 
 Set ws = Worksheets("Updated")
 Set target = ws.Range("E5:E" & Range("E5").End(xlDown)).Select

   ws1.Activate

  Range("A8").Select

   For r = 8 To ActiveCell.End(xlDown).Row

  Cells(r, 1).Select
  account = ActiveCell.Value

   For c = 2 To ActiveCell.End(xlToRight).Column

    ActiveCell.Offset(0, 1).Select        
    amount = ActiveCell.Value

   If ActiveCell.Value <> 0 Then

    target.Offset(1, 0).Value = amount       
    target.Range("E5").End(xlDown).Offset(0, 1) = account

    End If

     Next     
       Next

     ActiveCell.Offset(1, 0).Select

    End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

public static readonly BindableProperty ColumnsProperty = BindableProperty.Create("Columns", typeof(IEnumerable<Column>), typeof(TablePrac), new List<Column>());

public IEnumerable<Column> Columns
{
    set
    {
        SetValue(ColumnsProperty, value);
    }
    get
    {
        return (IList<Column>)GetValue(ColumnsProperty);
    }
}