Visual Basic移动所有其他列以创建一个长列B [英] Visual Basic move all other columns to create one long column B

查看:110
本文介绍了Visual Basic移动所有其他列以创建一个长列B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列数据,每排15行。列B是我想按顺序移动所有其他列的列。因此,列C的内容被削减并移动到已经在B中的等于。



到目前为止我有;

 '选择列
ActiveSheet.Range(B1,ActiveSheet.Range(B1)。End(xlDown))。选择
'剪切
Selection.Cut
'选择底部的单元格
ActiveSheet.Range(a1)。End(xlDown).Offset(1,0)。选择
'粘贴
ActiveSheet.Paste

我需要循环使其工作,循环遍历所有从A到FN的列。



提前感谢

解决方案

  Dim col As Range 

对于Works中的每个列(Sheet1)。列
如果(col.Column> 1和col.Column< ; 171)然后
Range(col.Rows(1),col.Rows(15))。选择
Selection.Cut
'选择A
ActiveSheet底部的单元格。 Range(a1)。End(xlDown).Offset(1,0).Select
ActiveSheet.Paste'Paste
End If
Next col
End Sub


I have a series of columns of data, each 15 rows deep. Column B is the column I want to move all other columns beneath in order. So the contents of column C gets cut and moved below that already in B and so on.

So far I have;

'Select a column
ActiveSheet.Range("B1", ActiveSheet.Range("B1").End(xlDown)).Select
'Cut
Selection.Cut
'Select cell at bottom of A
ActiveSheet.Range("a1").End(xlDown).Offset(1, 0).Select
'Paste
ActiveSheet.Paste

I need the loop to make it work, looping through all the columns from A to FN.

Thanks in advance.

解决方案

Dim col As Range

For Each col In Worksheets("Sheet1").Columns
    If (col.Column > 1 And col.Column < 171) Then
    Range(col.Rows(1), col.Rows(15)).Select
    Selection.Cut
    'Select cell at bottom of A
    ActiveSheet.Range("a1").End(xlDown).Offset(1, 0).Select
    ActiveSheet.Paste   'Paste
    End If
Next col
End Sub

这篇关于Visual Basic移动所有其他列以创建一个长列B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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