我有两个Excel文件。第一个包含与人相关的值,并且每月可用。
我想每月提取这些值并将它们导入第二个文件。第二个文件与第一个文件具有相似的结构,人名的顺序和行之间的距离是不同的。
这就是我所拥有的:
Private Sub CommandButton1_Click()
Dim wkb As Workbook
Dim wkb1 As Workbook
Dim wks As Worksheet
Dim wks1 As Worksheet
zeileErsterName = 8
spalteName = 2
ChDir "Dir"
Workbooks.Open Filename:= File2.xlsm"
Set wkb = Workbooks("File2.xlsm")
Set wkb1 = Workbooks("File1.xlsm")
Set wks = wkb.Worksheets("Jan-Dez")
Set wks1 = wkb1.Worksheets("Overview")
Monat = ListBox1.Value
MonatBudget = wks1.Cells.Find(What:=Monat).Column
Monat = Left(Monat, 3)
MonatBeleg = wks.Cells.Find(What:=Monat).Column
While Not IsEmpty(wks.Cells(zeileErsterName, spalteName))
Name = wks.Cells(zeileErsterName, spalteName).Value
zeileName = wks1.Cells.Find(What:=Name, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Row
zeileStaffingtage = zeileName + 1
wks1.Cells(zeileStaffingtage, MonatBudget).Value = wks.Cells(zeileErsterName, MonatBeleg).Value
Debug.Print wks1.Cells(zeileStaffingtage, MonatBudget).Value
zeileErsterName = zeileErsterName + 2
wks1.Name = "Overview"
Wend
Workbooks("File2.xlsm").Close SaveChanges:=False
End Sub
第一个问题是工作表的名称在循环中发生变化并取名人的名字。
第二个问题是File2中的值并不总是转移到File1中的正确位置。
感谢您的帮助。
File1是目标文件,我想将文件2中的值 - “Jan”列导入到相应名称的“Belegplan”行中。
亲切的问候