简体   繁体   English

将列添加到其他工作表

[英]Add column to different worksheet

I want to add a dynamic column into a different workbook. 我想将动态列添加到其他工作簿中。

Say I'm working in 1st Excel file and I want to add a column in 2nd Excel file. 假设我正在使用第一个Excel文件,并且想在第二个Excel文件中添加一列。

My code is adding the column into the 1st Excel file. 我的代码将列添加到第一个Excel文件中。

Sub insertColumn()
Range("B1").EntireColumn.Insert
End Sub

I also tried using 我也尝试使用

Woorkbook("newfile.xls").Worksheets("sheet1"). Range("B1").EntireColumn.Insert

other then the typo (use Workbooks instead of Woorkbook ) you also make sure that the name and extension of your file is correct 除了输入错误(使用Workbooks而不是Woorkbook )之外,您还要确保文件名和扩展名正确

for instance it may be "newfile.xls" or "newfile.xlsx" or "newfile.xlsm" 例如,它可能是“ newfile.xls”或“ newfile.xlsx”或“ newfile.xlsm”

if you know only have one excel file open whose name is "newfile" then you can omit the extension 如果您只知道打开一个名为“ newfile”的excel文件,则可以省略扩展名

Workbooks("newfile").Worksheets("sheet1").Range("B1").EntireColumn.Insert

Change the command to 将命令更改为

Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

or 要么

Worksheets("Sheet1").Columns("A:A").Insert

And check the correct parameters Shift and copyorigin 并检查正确的参数Shift和copyorigin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM