【问题标题】:Copy contents from a specific cell to an empty column based on number of rows from cells original column根据单元格原始列的行数将特定单元格的内容复制到空列
【发布时间】:2016-10-14 06:53:23
【问题描述】:

我目前面临的任务是每隔一列插入一列,将单元格的内容复制到新插入的列中,该范围是根据从中复制原始值的行数计算得出的。

重复直到所有插入的列都插入了复制值。查看插入的图像,例如原始数据和转换后的数据。

原始数据

根据单元格行数将第三个单元格的内容复制到范围内但左侧为空列的最终数据。

从代码的角度来看,我已经找到了如何插入空列,但计算行数并将第三个单元格从 B、D、F 复制到 ilastcol 到左列 A、C、E、n对于相同的范围,我无法理解。再加上在列数(ilastcol)中每隔三个单元格重复一次,我就无法理解。我查看了 row.count 来计算行长度。

Sub insert_column_after_interval_1()
' Function to insert a column every second column starting from 1.


Dim iLastCol As Integer
    iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column ' same as CTRL+RIGHT ARROW

    For colx = 1 To iLastCol Step 2

        Columns(colx).Insert Shift:=xlToRight

    Next

End Sub

任何帮助将不胜感激。

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    你必须更清楚,我不知道你还想做什么。

    我希望这就是你的意思。

    Sub insert_column_after_interval_1()
    
    
    
    Dim iLastCol As Integer
        iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
    
        For colx = iLastCol To 2 Step -1
    
            Columns(colx).Insert Shift:=xlToRight
    
        Next
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多