假设我在Excel中有Sheet(1)。现在我也有2500行,其中包含从A到BO的列的数据。现在我希望数据从这些工作表复制到同一个Excel文件的另一个工作表中2500行而不是整个列,而我只需要从A到AA数据的列要复制到新工作表。
那么如何使用VBscript构建它?
请帮帮我。
如何使用vbscript
将一张纸的行复制到另一张纸上答案 0 :(得分:3)
要将数据从一个工作表复制到另一个工作表,可以使用Copy en PasteSpecial命令。要使用.vbs
脚本执行此操作,请执行以下操作:
' Create Excel object
Set objExcel = CreateObject("Excel.Application")
' Open the workbook
Set objWorkbook = objExcel.Workbooks.Open _
("C:\myworkbook.xlsx")
' Set to True or False, whatever you like
objExcel.Visible = True
' Select the range on Sheet1 you want to copy
objWorkbook.Worksheets("Sheet1").Range("A1:AA25").Copy
' Paste it on Sheet2, starting at A1
objWorkbook.Worksheets("Sheet2").Range("A1").PasteSpecial
' Activate Sheet2 so you can see it actually pasted the data
objWorkbook.Worksheets("Sheet2").Activate
如果要在带有VBS宏的Excel中执行此操作,还可以调用复制和粘贴方法。只有您的工作簿对象类似于ActiveWorkbook
答案 1 :(得分:1)
此代码工作正常。只需复制并粘贴即可。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
答案 2 :(得分:0)
Sub buildMissingSheet(strMissingSheet) 'Just passing the missing sheet name in
' Master Sheet code
' Working on creating the "Master Sheet" at this time...May need to seperate the the code a little.
Dim GetRows1 As Worksheet
Dim GetRows2 As Worksheet
Dim PutRows As Worksheet
Dim sglRowNum As Single, i%
If strMissingSheet = strMASTERSHEET Then ' Create the strMASTERSHEET
Set GetRows1 = Sheets(strRAWDATA) ' These two sheets could be missing but will code around that later.
Set GetRows2 = Sheets(strDATAWITH) ' The two sheets I am getting rows from
'只是在这里创建一个新工作表,假设它已丢失 Worksheets.Add(After:= Worksheets(5))。Name = strMissingSheet Set PutRows = Sheets(strMissingSheet)'在声明之前必须创建缺失的工作表。
PutRows.Select 'Select the sheet being built.
With Cells(1, 1)
.Value = strRAWDATA 'Not copying rows here but left it in this example anyway
.AddComment
.Comment.Visible = False
.Select
.Comment.Text Text:= _
Chr(10) & "Name of sheet including header and the last 32 entries at the time this sheet was updated."
End With
'这是我们将整行从一张纸复制到另一张纸的地方。
GetRows1.Rows(1).Copy PutRows.Rows(2) 'Copy header row from existing sheet to "Master Sheet" for instance.
GetRows1.Select
sglRowNum = ReturnLastRow(ActiveSheet.Cells) 'return last row with data on active sheet
'我想要最后几行数据“32行”,所以找到了表格的末尾,这个代码可以在互联网上的几个地方找到,包括这个网站。
现在您可能一直在寻找的代码将32行数据从一张纸移到另一张。
For i = 1 To 32 'Start at row 3 on the Put sheet after sheet name and header.
GetRows1.Rows(sglRowNum - (32 - i)).Copy PutRows.Rows(i + 2)
Next i
结束子