根据单元格原始列的行数将内容从特定单元格复制到空列 [英] Copy contents from a specific cell to an empty column based on number of rows from cells original column

查看:81
本文介绍了根据单元格原始列的行数将内容从特定单元格复制到空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently faced with the task of inserting a column every second column, replicating the contents of cell into the newly inserted column for the range calculated on the number of rows from where the original value was copied from.

重复直到所有插入的列都插入一个复制值.请参阅插入的图像,例如原始数据和转换后的数据.

Repeat until all inserted columns have a copied value inserted. See inserted images for example of raw data and transformed data.

原始数据

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

Final Data with contents of third cell copied into range based on cells row count but empty column to left.

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

From a code point of view, I have located how to insert the empty column, but calculating the row count and copying the third cell from B, D, F, to ilastcol into the left columns A, C, E, n for same range eludes me. Plus repeating for every third cell within the number of columns (ilastcol) eludes me. I have looked at row.count to work out the row length.

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

任何帮助将不胜感激.

推荐答案

您必须更加清楚,我不知道您还想做什么.

You have to be more clear, I have no idea what else you want done.

我希望这就是你的意思.

I hope this is what you meant.

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

这篇关于根据单元格原始列的行数将内容从特定单元格复制到空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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