如何通过n值在单行中获取单元格的多个副本? [英] How to get multiple copies of a cell in a single row by n-number?

查看:193
本文介绍了如何通过n值在单行中获取单元格的多个副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用可以排序这个问题的vba代码。

I would like to use vba code that can sort this problem out.

我有一行,我想要同一行中每个单元格的多个副本。它需要通过n数字复制单元格。在行1中将是要复制的信息。在第2行中的n号。

I have a row and i want multiple copies of each cell in the same row. It needs to copy the cell by n-numbers. In row 1 will be the information to be copied. and in row 2 the n-number.

例如:

输入: number = 3)

Input: (say the n-number = 3)


  • John

  • Hendrik

  • Sara

输出:


  • John

  • 约翰

  • 约翰

  • Hendrik

  • >
  • Hendrik

  • Hendrik

  • Sara

  • Sara

  • Sara
    ....

  • John
  • John
  • John
  • Hendrik
  • Hendrik
  • Hendrik
  • Hendrik
  • Sara
  • Sara
  • Sara ....

希望有人能帮助我!

推荐答案

From:

To:

img src =https://i.stack.imgur.com/QvOi3.pngalt =enter image description here>

使用此代码:

Option Explicit

Sub CopyInAWeirdWay()
    Dim sh As Excel.Worksheet
    Dim LastRow As Long
    Dim currentCopyRow As Long
    Dim i As Long
    Dim k As Long

    Set sh = ActiveSheet
    LastRow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row
    currentCopyRow = 1

    For i = 1 To LastRow
        For k = 1 To sh.Cells(i, 2)
            sh.Cells(currentCopyRow, 3).Value = sh.Cells(i, 1).Value
            currentCopyRow = currentCopyRow + 1
        Next k
    Next i
End Sub

这篇关于如何通过n值在单行中获取单元格的多个副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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