I am sanitizing contact data in an excel spreadsheet in order to bulk upload into SalesForce. SalesForce, however, can only manage worksheets 100 contacts long. I want a macro that can split up a 700 row worksheet, for example, into seven workbooks, each containing 100 cell references.
I did some research on how to go about doing this, and I believe this is the only reference on StackOverflow to aid in this end: Solution for Dividing WorkSheet into Multiple Files with vba/excel/c#
Also, this solution looks promising, but I don't understand enough VBA to grasp it just yet: https://superuser.com/questions/57157/can-i-split-a-spreadsheet-into-multiple-files-based-on-a-column-in-excel-2007
However, the selected answer doesn't really serve my ends. Can someone point me in the right direction / enumerate the commands for doing this?
Here's what I have so far-- this appears to produce the right number of workbooks. Now I just need to figure out how to cut and paste 100 rows into each one.
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
Here's the code I'm using now:
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