20170728xlVBA改转置一例

Sub 导出()
    
    Dim Sht As Worksheet, ShtName As String
    Dim NextRow As Long, NextRow2 As Long
    Dim iRow As Long, Index As Long
    Dim mySum As Double
    iRow = 2

    Sheets("地块表").Activate

    Do While Cells(iRow, "F").Value <> ""

        ShtName = Cells(iRow, "F").Value
        Set Sht = Sheets(ShtName)

        NextRow = Sht.Range("C65536").End(xlUp).Row + 1

        If NextRow = 3 Then
            mySum = 0
            Index = 0
        End If

        Index = Index + 1
        
        If Index <= 39 Then
            Sht.Cells(NextRow, "A").Value = Cells(iRow, "A").Value    '序号
            Sht.Cells(NextRow, "C").Value = Cells(iRow, "B").Value    '农户代表
            Sht.Cells(NextRow, "G").Value = Cells(iRow, "C").Value    '地块数
            Sht.Cells(NextRow, "K").Value = Cells(iRow, "D").Value    '承包面积
        Else
            NextRow2 = Sht.Range("O65536").End(xlUp).Row + 1
            Sht.Cells(NextRow2, "O").Value = Cells(iRow, "A").Value    '序号
            Sht.Cells(NextRow2, "Q").Value = Cells(iRow, "B").Value    '农户代表
            Sht.Cells(NextRow2, "U").Value = Cells(iRow, "C").Value    '地块数
            Sht.Cells(NextRow2, "Y").Value = Cells(iRow, "D").Value    '承包面积
        End If

        mySum = mySum + Cells(iRow, "D").Value    '累计承包面积
        Sht.Range("Q42").Value = mySum

        iRow = iRow + 1
        ShtName = Cells(iRow, "F").Value
    Loop

    MsgBox ("ok")
End Sub

  

转载于:https://www.cnblogs.com/nextseven/p/7248510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值