作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
VBA 中的 Excel 宏 2016。需要以不同的顺序将 8 个单独的列从一张纸复制到另一张纸。尝试过,但粘贴总是在同一列 A 中完成...
代码以:
Sub Button1_Click()
Dim ultima_fila As Long
Dim rango, columna As String
Sheets("Validation by rules").Select
ultima_fila = Cells(Rows.Count, 1).End(xlUp).Row
' TableName
columna = "A"
rango = columna & "1:" & columna & CStr(ultima_fila)
MsgBox rango
range(rango).Copy
Sheets("TMP").Paste
'TableField
columna = "B"
rango = columna & "1:" & columna & CStr(ultima_fila)
MsgBox rango
range(rango).Copy
Sheets("TMP").Paste
最佳答案
您没有告诉代码粘贴到哪里:Sheets("TMP").Paste
.您只命名工作表而不命名列。
还可以使用循环,这样您就不需要继续重新输入相同的内容:
Sub Button1_Click()
Dim ultima_fila As Long
Dim columnOrd As Variant
columnOrd = Array("A", "B", "C", "G", "F", "R", "S", "T")
With Sheets("Validation by rules")
ultima_fila = .Cells(.Rows.Count, 1).End(xlUp).Row
Dim i As Long
For i = 1 To 8
MsgBox .Range(.Cells(1, columnord(i - 1)), .Cells(ultima_fila, columnord(i - 1))).Address
.Range(.Cells(1, columnord(i - 1)), .Cells(ultima_fila, columnord(i - 1))).Copy Destination:=Sheets("TMP").Cells(1, i)
Next i
End With
End Sub
关于vba - 从 sheet1 列 A、B、C、G、F、R、S、T 复制到列 A、B、C、D、E、F、G、H 中的表 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51602689/
我是一名优秀的程序员,十分优秀!