I'm creating a UserForm that allows the user to select a sheet to perform the macro on and enter in X amount of rows in which the ultimate goal is to split the selected sheet into multiple sheets by X amount of rows.
Code:
Dim rowCount As Long Dim rowEntered As Long Dim doMath As Long rowCount = Sheets(Me.ComboBox1.Value).Cells(Rows.Count, "A").End(xlUp).Row 'Count Number of Rows in selected Sheet rowEntered = Val(Me.TextBox1.Value) 'User enters X amount If rowCount < rowEntered Then MsgBox "Enter in another number" Else doMath = (rowCount / rowEntered) For i = 1 to doMath Sheets.Add.name = "New-" & i Next i 'Help!! For i= 1 to doMath Sheets("New-" & i).Rows("1:" & rowEntered).Value = Sheets(Me.ComboBox1.Value).Rows("1:" & rowEntered).Value Next i End If The last section of code is where I need help because I can't seem to figure out how to do it properly..
The code currently loops through the newly added sheets and "pastes" in the same rows. For example, if the sheet selected has 1000 rows (rowCount), and rowEntered is 500, then it would create 2 new sheets. Rows 1-500 should go in New-1 and Rows 501-1000 should go into New-2. How can I achieve this?
rangeinstead? Create range variables that holds the rows then drop them.