rfletcher35
Active Member
- Joined
- Jul 20, 2011
- Messages
- 300
- Office Version
- 365
- Platform
- Windows
Hi Guys
I have a routine that populates multiple sheets in multiple pages from one set of data. One these multiple sheets column C on my sheets I would like to keep to a max height of 180.
If the text placed in this column goes over this height then I would like vba to place a scroll bar in the cell. I need it from row 5 to 100.
Is this possible? I have placed where I need the code below
In addition if there is a neat way to abbreviate the below where I try to neaten the worksheet I am open to suggestions.
Thanks
Fletch
Sub PopulateTabs()
Dim lastRow As Long, r As Long
With Worksheets("Stats")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
'Loop through clients in Stats column B from row 3
For r = 3 To lastRow
'Filter Import column F on this client
Worksheets("Import").Range("A1").AutoFilter Field:=6, Criteria1:=.Cells(r, "B").Value
'Stats column M is destination sheet name - clear sheet and copy filtered data to A4
Worksheets(.Cells(r, "M").Value).Cells.ClearContents
Worksheets("Import").UsedRange.SpecialCells(xlCellTypeVisible).Copy
Worksheets(.Cells(r, "M").Value).Range("A4").PasteSpecial
ActiveWindow.Zoom = 90
Format_Sheet Worksheets(.Cells(r, "M").Value)
'ws.Range("A4:A600,E4:E600,G4:G600,J4:J600,L4:L600,N4:AA600,AD4:AD600,AH4:AI600").Delete Shift:=xlToLeft
Worksheets(.Cells(r, "M").Value).Rows("4:4").HorizontalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("4:4").VerticalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("4:4").WrapText = True
Worksheets(.Cells(r, "M").Value).Rows("4:4").Orientation = 0
Worksheets(.Cells(r, "M").Value).Rows("4:4").AddIndent = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").IndentLevel = 0
Worksheets(.Cells(r, "M").Value).Rows("4:4").ShrinkToFit = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").ReadingOrder = xlContext
Worksheets(.Cells(r, "M").Value).Rows("4:4").MergeCells = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").Font.Bold = True
Worksheets(.Cells(r, "M").Value).Rows("5:100").HorizontalAlignment = xlLeft
Worksheets(.Cells(r, "M").Value).Rows("5:100").VerticalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("5:100").WrapText = True
Worksheets(.Cells(r, "M").Value).Rows("5:100").Orientation = 0
Worksheets(.Cells(r, "M").Value).Rows("5:100").AddIndent = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").IndentLevel = 0
Worksheets(.Cells(r, "M").Value).Rows("5:100").ShrinkToFit = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").ReadingOrder = xlContext
Worksheets(.Cells(r, "M").Value).Rows("5:100").MergeCells = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").EntireRow.AutoFit
Worksheets(.Cells(r, "M").Value).Rows("5:100").Font.Size = 9
Worksheets(.Cells(r, "M").Value).Range("A4").FormulaR1C1 = "Autotask Ticket Number"
Worksheets(.Cells(r, "M").Value).Range("B4").FormulaR1C1 = "Title"
Worksheets(.Cells(r, "M").Value).Range("D4").FormulaR1C1 = "Company"
Worksheets(.Cells(r, "M").Value).Range("F4").FormulaR1C1 = "Status"
Worksheets(.Cells(r, "M").Value).Range("G4").FormulaR1C1 = "Source"
Worksheets(.Cells(r, "M").Value).Range("H4").FormulaR1C1 = "Primary Resource"
Worksheets(.Cells(r, "M").Value).Range("L4").FormulaR1C1 = "Due Date/Time"
Worksheets(.Cells(r, "M").Value).Columns("A:A").ColumnWidth = 16
Worksheets(.Cells(r, "M").Value).Columns("C:C").ColumnWidth = 100
Worksheets(.Cells(r, "M").Value).Columns("D:D").ColumnWidth = 15
Worksheets(.Cells(r, "M").Value).Columns("E:E").ColumnWidth = 13
Worksheets(.Cells(r, "M").Value).Columns("F:F").ColumnWidth = 9
Worksheets(.Cells(r, "M").Value).Columns("G:G").ColumnWidth = 8
Worksheets(.Cells(r, "M").Value).Columns("H:H").ColumnWidth = 18
Worksheets(.Cells(r, "M").Value).Columns("I:I").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("J:J").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("K:K").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("L:L").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("M:M").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("N:N").ColumnWidth = 16
Next
Worksheets("Import").AutoFilterMode = False
Application.CutCopyMode = False
End With
I have a routine that populates multiple sheets in multiple pages from one set of data. One these multiple sheets column C on my sheets I would like to keep to a max height of 180.
If the text placed in this column goes over this height then I would like vba to place a scroll bar in the cell. I need it from row 5 to 100.
Is this possible? I have placed where I need the code below
In addition if there is a neat way to abbreviate the below where I try to neaten the worksheet I am open to suggestions.
Thanks
Fletch
Sub PopulateTabs()
Dim lastRow As Long, r As Long
With Worksheets("Stats")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
'Loop through clients in Stats column B from row 3
For r = 3 To lastRow
'Filter Import column F on this client
Worksheets("Import").Range("A1").AutoFilter Field:=6, Criteria1:=.Cells(r, "B").Value
'Stats column M is destination sheet name - clear sheet and copy filtered data to A4
Worksheets(.Cells(r, "M").Value).Cells.ClearContents
Worksheets("Import").UsedRange.SpecialCells(xlCellTypeVisible).Copy
Worksheets(.Cells(r, "M").Value).Range("A4").PasteSpecial
ActiveWindow.Zoom = 90
Format_Sheet Worksheets(.Cells(r, "M").Value)
'ws.Range("A4:A600,E4:E600,G4:G600,J4:J600,L4:L600,N4:AA600,AD4:AD600,AH4:AI600").Delete Shift:=xlToLeft
Worksheets(.Cells(r, "M").Value).Rows("4:4").HorizontalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("4:4").VerticalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("4:4").WrapText = True
Worksheets(.Cells(r, "M").Value).Rows("4:4").Orientation = 0
Worksheets(.Cells(r, "M").Value).Rows("4:4").AddIndent = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").IndentLevel = 0
Worksheets(.Cells(r, "M").Value).Rows("4:4").ShrinkToFit = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").ReadingOrder = xlContext
Worksheets(.Cells(r, "M").Value).Rows("4:4").MergeCells = False
Worksheets(.Cells(r, "M").Value).Rows("4:4").Font.Bold = True
Worksheets(.Cells(r, "M").Value).Rows("5:100").HorizontalAlignment = xlLeft
Worksheets(.Cells(r, "M").Value).Rows("5:100").VerticalAlignment = xlCenter
Worksheets(.Cells(r, "M").Value).Rows("5:100").WrapText = True
Worksheets(.Cells(r, "M").Value).Rows("5:100").Orientation = 0
Worksheets(.Cells(r, "M").Value).Rows("5:100").AddIndent = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").IndentLevel = 0
Worksheets(.Cells(r, "M").Value).Rows("5:100").ShrinkToFit = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").ReadingOrder = xlContext
Worksheets(.Cells(r, "M").Value).Rows("5:100").MergeCells = False
Worksheets(.Cells(r, "M").Value).Rows("5:100").EntireRow.AutoFit
Worksheets(.Cells(r, "M").Value).Rows("5:100").Font.Size = 9
Worksheets(.Cells(r, "M").Value).Range("A4").FormulaR1C1 = "Autotask Ticket Number"
Worksheets(.Cells(r, "M").Value).Range("B4").FormulaR1C1 = "Title"
Worksheets(.Cells(r, "M").Value).Range("D4").FormulaR1C1 = "Company"
Worksheets(.Cells(r, "M").Value).Range("F4").FormulaR1C1 = "Status"
Worksheets(.Cells(r, "M").Value).Range("G4").FormulaR1C1 = "Source"
Worksheets(.Cells(r, "M").Value).Range("H4").FormulaR1C1 = "Primary Resource"
Worksheets(.Cells(r, "M").Value).Range("L4").FormulaR1C1 = "Due Date/Time"
Worksheets(.Cells(r, "M").Value).Columns("A:A").ColumnWidth = 16
Worksheets(.Cells(r, "M").Value).Columns("C:C").ColumnWidth = 100
Worksheets(.Cells(r, "M").Value).Columns("D:D").ColumnWidth = 15
Worksheets(.Cells(r, "M").Value).Columns("E:E").ColumnWidth = 13
Worksheets(.Cells(r, "M").Value).Columns("F:F").ColumnWidth = 9
Worksheets(.Cells(r, "M").Value).Columns("G:G").ColumnWidth = 8
Worksheets(.Cells(r, "M").Value).Columns("H:H").ColumnWidth = 18
Worksheets(.Cells(r, "M").Value).Columns("I:I").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("J:J").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("K:K").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("L:L").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("M:M").EntireColumn.AutoFit
Worksheets(.Cells(r, "M").Value).Columns("N:N").ColumnWidth = 16
Next
Worksheets("Import").AutoFilterMode = False
Application.CutCopyMode = False
End With