复制每第n个Cell [英] Copy every nth Cell

查看:81
本文介绍了复制每第n个Cell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将每个第n个单元格复制到另一个工作表上的单个列中。例如,假设我有一个H1值,每96个单元格对应一个值。我想复制H2 + n96,其中n是一些整数,直到我的数据集结束。我想将
粘贴到单独工作表的列中。然后,我想从单元格H3开始并复制单元格H3 + n96并将其移动到另一个工作表中的列中。

I am trying to copy every nth cell into a single column on another worksheet. For example, say I have a value in H1 and corresponding values every 96 cells. I would want to copy H2 + n96 where n is some integer until the end of my data set. I want to paste that into a column on a separate worksheet. Then after that, I want to start at cell H3 and copy the cells H3 + n96 and move that into a column in another worksheet.

我试图整天解决这个问题而没有任何成功。我认为创建一个复制序列  H2 + n96并将其粘贴到另一个工作表中的循环是个好主意。这是我的ODgenerator子。然后我认为我可以在其周围放置一个外部的
循环,只需增加我的StartCopyRow和我的StartPasteColumn并让它执行其余的复制/粘贴序列(H3 + n96,H4 + n96等)但是  ;只显示第一列...我需要帮助 

I've tried to solve this problem all day without any success. I thought it would be a good idea to create a loop that copies the sequence H2 + n96 and pastes it into another sheet. This is my ODgenerator sub. Then I thought that I could put an external loop around that and just increment my StartCopyRow and my StartPasteColumn and have it carry out the rest of the copy/paste sequences (H3 + n96, H4 + n96, etc) but only the first column appears...i need help 

Sub Landon()

Sub Landon()

Dim StartCopyRow As Integer

Dim StartCopyColumn As Integer

Dim StartPasteRow As Integer

Dim StartPasteColumn As Integer

Dim StartCopyRow As Integer
Dim StartCopyColumn As Integer
Dim StartPasteRow As Integer
Dim StartPasteColumn As Integer

StartCopyRow = 2

StartCopyColumn = 8

StartPasteRow = 2

StartPasteColumn = 1

StartCopyRow = 2
StartCopyColumn = 8
StartPasteRow = 2
StartPasteColumn = 1

执行

致电ODGenerator(StartCopyRow,StartCopyColumn,StartPasteRow,StartPasteColumn)

Call ODGenerator(StartCopyRow, StartCopyColumn, StartPasteRow, StartPasteColumn)

StartCopyRow = StartCopyRow + 1

StartPasteColumn = StartPasteColumn + 1

StartCopyRow = StartCopyRow + 1
StartPasteColumn = StartPasteColumn + 1

Loop Until StartCopyRow = 97

Loop Until StartCopyRow = 97

End Sub

 

Sub ODGenerator(CopyRow As Integer,CopyColumn As Integer,PasteRow As Integer,PasteColumn As Integer)

    

   请按
       单元格(CopyRow,CopyColumn)。复制表格("OD")。单元格(PasteRow,PasteColumn)

        CopyRow = CopyRow + 96

        PasteRow = PasteRow + 1

       

    Loop Until IsEmpty(Cells(CopyRow,CopyColumn))

Sub ODGenerator(CopyRow As Integer, CopyColumn As Integer, PasteRow As Integer, PasteColumn As Integer)
   
    Do
        Cells(CopyRow, CopyColumn).Copy Sheets("OD").Cells(PasteRow, PasteColumn)
        CopyRow = CopyRow + 96
        PasteRow = PasteRow + 1
       
    Loop Until IsEmpty(Cells(CopyRow, CopyColumn))

End Sub

推荐答案

你好mynamealreadyinuse ,

Hi mynamealreadyinuse,

您需要控制变量。您只能看到1列,因为您的CopyRow是通过ByRef传递的,而在下一列中,空白单元格是从OD数据下方复制的。尝试这样:

You need to have control over your variables. You can see only 1 column because your CopyRow is passed ByRef and in next column empty cell is copied from below your OD data. Try like this:

Sub ODGenerator(ByVal CopyRow As Integer, ByVal CopyColumn As Integer, ByVal PasteRow As Integer, ByVal PasteColumn As Integer)

通过传递变量ByRef,你在这里更改你的StartCopyRow参数:

StartCopyRow = StartCopyRow + 1

and here:

CopyRow = CopyRow + 96

By passing variables ByRef you are changing your StartCopyRow argument in here:
StartCopyRow = StartCopyRow + 1
and here:
CopyRow = CopyRow + 96

查看传递变量参考和按价值


这篇关于复制每第n个Cell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆