Anyone know VBA?

Home Archive Serious Business Anyone know VBA?
LJ's avatar

LJ

Senior Member

16,351 posts
Jan 22, 2014 8:44 PM
So I have ~39,000 lines of data and I need to split it into populations of 300 over 120 sheets. Everything is in 1 column and it doesnt need sorted in any particular fashion.

THis is the code I was working with


Option Explicit
Sub ColumnToSheets()
Dim LR As Long, Rw As Long, Sz As Long
Sz = Application.InputBox(300, Type:=1)
If Sz = 0 Then Exit Sub
Application.ScreenUpdating = False
With ActiveSheet
LR = .Range(“A1” & .Rows.Count).End(xlUp).Row
For Rw = 1 To LR Step Sz
Sheets.Add after:=Sheets(Sheets.Count)
.Range(“A” & Rw).Resize(Sz).Copy Range(A1, [A40000])
Next Rw
.Activate
End With
Application.ScreenUpdating = True
MsgBox “Done”
End Sub


But its not really working, this part is erroring out
LR = .Range(“A1” & .Rows.Count).End(xlUp).Row
For Rw = 1 To LR Step Sz
I have really only ever coded alerts and prompts so I am kind of at a loss here
Jan 22, 2014 8:44pm
Ironman92's avatar

Ironman92

Administrator

49,363 posts
Jan 22, 2014 8:57 PM
I can help you with the 5 components of physical fitness....but I'm not sure on this one.
Jan 22, 2014 8:57pm
Devils Advocate's avatar

Devils Advocate

Brudda o da bomber

4,539 posts
Jan 23, 2014 8:57 AM
Finally, proof that LJ does not know everthing.


You can rest easy now boys..
Jan 23, 2014 8:57am
Belly35's avatar

Belly35

Elderly Intellectual

9,716 posts
Jan 23, 2014 9:40 AM
LJ;1570919 wrote:So I have ~39,000 lines of data and I need to split it into populations of 300 over 120 sheets. Everything is in 1 column and it doesnt need sorted in any particular fashion.

THis is the code I was working with


Option Explicit
Sub ColumnToSheets()
Dim LR As Long, Rw As Long, Sz As Long
Sz = Application.InputBox(300, Type:=1)
If Sz = 0 Then Exit Sub
Application.ScreenUpdating = False
With ActiveSheet
LR = .Range(“A1” & .Rows.Count).End(xlUp).Row
For Rw = 1 To LR Step Sz
Sheets.Add after:=Sheets(Sheets.Count)
.Range(“A” & Rw).Resize(Sz).Copy Range(A1, [A40000])
Next Rw
.Activate
End With
Application.ScreenUpdating = True
MsgBox “Done”
End Sub


But its not really working, this part is erroring out
LR = .Range(“A1” & .Rows.Count).End(xlUp).Row
For Rw = 1 To LR Step Sz
I have really only ever coded alerts and prompts so I am kind of at a loss here
I got this:

L/R = .Runge ....... (“A1” & .Rope.****).Ed....... (xlUp). mofo
For Raw = 1 two L/R Sheep Sz

Hope this hleps
Jan 23, 2014 9:40am
G

gut

Senior Member

15,058 posts
Jan 23, 2014 4:19 PM
Just record a macro inserting a new worksheet, then selecting/cutting/pasting to that new worksheet. Google how to do a "For Next i" loop and edit the macro for i = 1 to 300. I think your cell references will be something like 1300*i
Jan 23, 2014 4:19pm
LJ's avatar

LJ

Senior Member

16,351 posts
Jan 23, 2014 6:27 PM
gut;1571282 wrote:Just record a macro inserting a new worksheet, then selecting/cutting/pasting to that new worksheet. Google how to do a "For Next i" loop and edit the macro for i = 1 to 300. I think your cell references will be something like 1300*i
That just loops a finite number. I got the code figured out(a lot of help from a lot of people). I can post it if anyone wants.
Jan 23, 2014 6:27pm
Commander of Awesome's avatar

Commander of Awesome

Senior Pwner

23,151 posts
Jan 23, 2014 6:31 PM
LJ;1571343 wrote:That just loops a finite number. I got the code figured out(a lot of help from a lot of people). I can post it if anyone wants.
Nope, DGAF
Jan 23, 2014 6:31pm