我需要在不同的工作簿(控股和子公司)之间合并 2 个学生的注册。因此,当我单击“生成图形”按钮时,数据将合并到“总计”表中,然后计算课程数量(Excel、Word、Access ......)并在“图形”表中生成图形。第一次测试没问题,但是当我再次点击时,列表随着子公司工作簿的相同数据而增加。我需要更改代码中的某些内容,但我不知道是什么。你可以帮帮我吗?我的代码是:
Sub GerarGrafico()
Dim k As Long
'copying data of the “Course Booking” Sheet
Sheets("Course Booking").Select
Range("A1").Select
linini = 2
'Select the last row
Selection.End(xlDown).Select
linfin = Selection.Row
'Select the last column
Selection.End(xlToRight).Select
colfin = Selection.Column
Range(Cells(linini, 1), Cells(linfin, colfin)).Select
Selection.Copy
'复制工作表“总计”中的数据
Sheets("Total").Select
Cells(linini, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
‘Copying data of the “reserva filial.xlsm”
caminho = ThisWorkbook.Path
Workbooks.Open caminho & "\" & "reserva filial.xlsm"
'copying data
Range("A1").Select
linini2 = 2
'Select the last row
Selection.End(xlDown).Select
linfin2 = Selection.Row
'Select the last column
Selection.End(xlToRight).Select
colfin2 = Selection.Column
Range(Cells(linini2, 1), Cells(linfin2, colfin2)).Select
Selection.Copy
Windows("Trabalho_Felipe Granado_v8.xlsm").Activate
Sheets("Total").Select
'Select the last row with value
Selection.End(xlDown).Select
k = ActiveCell.Row + 1
Cells(k, 1).Activate
Application.Windows("reserva filial.xlsm").Visible = False
'pasting data "reserva filial.xlsm" in the sheet "Total"
ActiveSheet.Paste
Application.CutCopyMode = False
Columns.HorizontalAlignment = xlCenter