Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2626|回复: 1

[已解决]修改或重新写个宏

[复制链接]
发表于 2016-4-7 09:42 | 显示全部楼层 |阅读模式
本帖最后由 乐乐2006201506 于 2016-4-7 09:44 编辑

需要将sheet2中B列从B2开始的数据(有多少个填多少个),填到晋档个人表 (2)中每个表(数据都不相同,现在是我把所有的数据删除了,所以是空表)姓名后边的单元格(B5,B26……)中。请大神帮忙。谢谢!

Sub 填数据()
'
    Selection.NumberFormatLocal = "G/通用格式"
    B5 = "=Sheet2!R[-3]C"
    With Range("A20:A" & Range("A636").End(3).Row)
        Set c = .Find("姓  名")
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                Range("B5").Copy c
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
End Sub

最佳答案
2016-4-7 11:40
Sub 填数据() '
    With Sheets("Sheet2")
        For i = 1 To [a65536].End(3).Row
            If Cells(i, 1) = "姓  名" Then
                n = n + 1
                Cells(i, 2) = .Cells(n + 1, 2)
                'Cells(i + 1, 4) = .Cells(n + 1, 3) '.......  工作时间
                '.......把sheet2的相关内容填到当前表中
                '...............
                i = i + 20         '尽量靠近下一表的起始位置
            End If
        Next
    End With
End Sub

Book1 0.rar

207.53 KB, 下载次数: 20

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-4-7 11:40 | 显示全部楼层    本楼为最佳答案   
Sub 填数据() '
    With Sheets("Sheet2")
        For i = 1 To [a65536].End(3).Row
            If Cells(i, 1) = "姓  名" Then
                n = n + 1
                Cells(i, 2) = .Cells(n + 1, 2)
                'Cells(i + 1, 4) = .Cells(n + 1, 3) '.......  工作时间
                '.......把sheet2的相关内容填到当前表中
                '...............
                i = i + 20         '尽量靠近下一表的起始位置
            End If
        Next
    End With
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 10:13 , Processed in 0.689418 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表