我正在清理Excel電子表格中的聯繫人數據,以批量上傳到SalesForce中。然而,SalesForce只能管理長達100個聯繫人的工作表。我想要一個可以將700行工作表分成7個工作簿的宏,每個工作簿包含100個單元格引用。VBA宏將一個工作表分成幾個工作簿,基於工作表中的行數
我做了如何去這樣做了一些研究,我相信這是在計算器上唯一的參考爲此,以幫助: Solution for Dividing WorkSheet into Multiple Files with vba/excel/c#
此外,該解決方案看起來很有希望,但我不瞭解足夠的VBA以便掌握它:https://superuser.com/questions/57157/can-i-split-a-spreadsheet-into-multiple-files-based-on-a-column-in-excel-2007
但是,選定的答案並不真正服務於我的目的。有人能指出我正確的方向/列舉這樣做的命令嗎?
以下是我到目前爲止 - 這似乎產生正確數量的工作簿。現在我只需要弄清楚如何在每一行中剪切和粘貼100行。
Sub Macro12()
Dim wb As Workbook
Dim p As Double
Dim p_quotient As Double
Application.ScreenUpdating = False
p = ActiveSheet.UsedRange.Rows.Count
p_quotient = p/100
p_quotient = Application.WorksheetFunction.RoundUp(p_quotient, 0)
For i = 1 To p_quotient
Workbooks.Add
Set wb = ActiveWorkbook
ThisWorkbook.Activate
wb.SaveAs ThisWorkbook.Path & "test" & i
wb.Close
Next i
Application.ScreenUpdating = True
Set wb = Nothing
End Sub
這是我現在使用的代碼:
Sub Macro12()
Dim wb As Workbook
Dim ThisSheet As Worksheet
Dim NumOfColumns As Integer
Dim RangeToCopy As Range
Dim WorkbookCounter As Integer
Dim myDate As String
myDate = Format(Date, "yyyy.mm.dd")
Set ThisSheet = ThisWorkbook.ActiveSheet
NumOfColumns = ThisSheet.UsedRange.Columns.Count
WorkbookCounter = 1
For p = 1 To ThisSheet.UsedRange.Rows.Count Step 101
Set wb = Workbooks.Add
Set RangeToCopy = ThisSheet.Range(ThisSheet.Cells(p, 1), ThisSheet.Cells(p + 100, NumOfColumns))
RangeToCopy.Copy wb.Sheets(1).Range("A1")
wb.SaveAs ThisWorkbook.Path & "\Salesforce Lead Conversion " & myDate & " Part " & WorkbookCounter & ".xls"
wb.Close
WorkbookCounter = WorkbookCounter + 1
Next p
Application.ScreenUpdating = True
Set wb = Nothing
End Sub
什麼是你的代碼迄今使用? – enderland