简体   繁体   English

查找范围内的文本,然后将下一个Activecell.offset(1,1)16个单元格复制到目标位置

[英]Find a text in a range and copy the next Activecell.offset(1,1)16 cells to destination

I have a range I13 to I6076. 我的范围是I13至I6076。 I am starting at first I13 cell and finding a match in Range("D12:D103333"). 我从第一个I13单元格开始,并在Range(“ D12:D103333”)中找到一个匹配项。 If it finds a match in Col D then it should offset Activecell.offset(1,1) from Col D cell and copy the next 16 cells(vertical copy) to corresponding I13 row(horizontal paste). 如果在Col D中找到匹配项,则应该从Col D单元格偏移Activecell.offset(1,1),然后将接下来的16个单元格(垂直副本)复制到相应的I13行(水平粘贴)。 and then move on to I14 and so on. 然后转到I14,依此类推。 I have created a do while loop to find the cells in the range Range("D12:D103333"), but how do I offset and copy the next 16 cells. 我创建了一个do while循环来查找Range(“ D12:D103333”)范围内的单元格,但是如何偏移并复制接下来的16个单元格。 and then go to next cell in col I. Any help would be greatly appreciated. 然后转到第I列的下一个单元。任何帮助将不胜感激。 Many Thanks. 非常感谢。 Code is below. 代码如下。

Sub Kantar() 子Kantar()

Dim Category As String
i As Integer

Range("I13").Select
Do While Not IsEmpty(ActiveCell)
    Category = ActiveCell.Value
    Range("D12:D103333").Find(What:=Category, MatchCase:=True).Select


ActiveCell.Offset(1, 0).Select
Loop

End Sub 结束子

Try doing something like this: 尝试做这样的事情:

1) Once the cell is found, activecell.offset(1,1) 1)一旦找到该单元格, activecell.offset(1,1)

2) From there, use your activecell.address and activecell.address + 16 as a range to do range.copy 2)从那里,使用您的activecell.addressactivecell.address + 16作为范围来做range.copy

3) Offset the active cell to where you want to paste. 3)将活动单元偏移到要粘贴的位置。

4) Paste Special with transpose to transpose it horizontally (use macro recorder to show you how if you are unsure) 4)使用“转置”粘贴“特殊”,将其水平转置(使用宏记录器向您展示不确定的方式)

5) Offset back to original cell (coordinates based on where you end up) 5)向后偏移到原始单元格(坐标基于您最终的位置)

6) Offset down 1 cell and continue the loop. 6)偏移1个单元格并继续循环。 (Which you already have coded) (您已经编码了)

I'd give actual code but I'm not at a PC. 我会提供实际的代码,但我不在PC上。 Hopefully these steps still help if someone else doesn't give you the code :) 如果其他人没有给您代码,希望这些步骤仍然有用:)

Firstly I would like to Thank Busse for providing me the logical steps to get my answer. 首先,我要感谢Busse为我提供了获得答案的合理步骤。 It was Super helpful. 超级有帮助。 So I am copying my code below which might help several users with similar issues. 因此,我在下面复制我的代码,这可能会帮助一些遇到类似问题的用户。 Thanks:)) 谢谢:))

Sub Kantar2()

    Dim Category As String, i As Long, FinalRow As Long
    Dim Rng As Range, MyCell As Range

    Application.ScreenUpdating = False
    i = 10
    FinalRow = Cells(Rows.Count, 4).End(xlUp).Row
    Set Rng = Range("I13:I6086")
    For Each MyCell In Rng
        Category = MyCell.Value
        Range(Cells(i, 4), Cells(FinalRow, 4)).Find(What:=Category, MatchCase:=True).Select
        i = ActiveCell.Row
        ActiveCell.Offset(1, 1).Select
        Range(Cells(ActiveCell.Row, 5), Cells(ActiveCell.Row + 15, 5)).Copy
        MyCell.Offset(0, 1).PasteSpecial Transpose:=True
    Next MyCell
    Application.ScreenUpdating = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM