I am trying to loop through all the sheets in my workbook and rearrange some data. So far I have been unsucessful for some reason. I think I have the loop and everything set up correctly, but the macro gets hung up on one sheet and executes the code over and over again on the same sheet without looping. Here is what I have:
I really can't figure out why it won't loop through the sheets, so any help would be awesome, thanks!
Code:
Sub DBOrderIt()Application.ScreenUpdating = False
Dim TblRng As Range
Dim topcell As Range
Dim bottcell As Range
Dim ws As Worksheet
For Each ws In Worksheets
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select
Selection.Cut Destination:=Range("B2")
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B" & Range("A65536").End(xlUp).Row)
Range("B2:B" & Range("A65536").End(xlUp).Row).Select
Set TblRng = Range("D1:X1")
For Each cell In TblRng
On Error Resume Next
Range(cell.Offset(1, 0), cell.Offset(Range("A65536").End(xlUp).Row, 0)).Copy
Range("C" & Range("C65536").End(xlUp).Row + 1).Select
ActiveSheet.Paste
cell.Copy
Range("B" & Range("B65536").End(xlUp).Row + 1).Select
ActiveSheet.Paste
'AutoFill Here
Selection.AutoFill Destination:=Range("B" & (Range("B65536").End(xlUp).Row) & ":B" & (Range("C65536").End(xlUp).Row))
Next cell
Next ws
Application.ScreenUpdating = True
End Sub
I really can't figure out why it won't loop through the sheets, so any help would be awesome, thanks!