icklemiller
New Member
- Joined
- Apr 8, 2011
- Messages
- 43
Hi,
I'm running the macro below, and looking to add in some code to auto resize the width of the columns. I've tried to manually adjust, but every time i run the macro, they jump back to the default.
Code is as follows:
Thanks in advance for any assistance you can offer!
I'm running the macro below, and looking to add in some code to auto resize the width of the columns. I've tried to manually adjust, but every time i run the macro, they jump back to the default.
Code is as follows:
Code:
Sub JobSummary()
Dim wsSum As Worksheet
Dim stStage As String
Dim inJob As Integer
Dim ws As Worksheet
Dim c As Range
Dim r As Long
Application.ScreenUpdating = False
' ENSURE SUMMARY SHEET EXISTS
On Error Resume Next
With ThisWorkbook
Set wsSum = .Worksheets("Summary")
If wsSum Is Nothing Then
Set wsSum = .Worksheets.Add
wsSum.Name = "Summary"
End If
End With
' On Error GoTo EH:
With wsSum
' PREP SUMMARY SHEET
.Cells.Delete
.Range("A1").Value = "Setting Out"
.Range("A2").Value = "Machine Shop"
.Range("A3").Value = "Joineryshop"
.Range("A4").Value = "Stair Dept"
.Range("A5").Value = "Polishing Shop"
.Range("A6").Value = "Delivery"
.Range("A1:A6").Font.Bold = True
End With
stStage = "A:A" 'Job Stage Column; in this example, Column A
inJob = 1 'Job Name column # - Job Stage column #; in this example, Job names are in Column B
' Loop through workbook, copying job names from each sheet to the correct column stage on the summary sheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> wsSum.Name Then
' Loops through each cell in the job stage column
For Each c In Intersect(ws.UsedRange, ws.Range(stStage))
If InStr(1, "smjstpd", c.Value, vbTextCompare) > 0 Then c.Offset(0, inJob).Resize(, 10).Copy
' Copies job name to the correct stage
Select Case c.Value
Case "s"
r = wsSum.Cells.Find(What:="Machine Shop", After:=wsSum.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows).Row
wsSum.Range("A" & r).Insert Shift:=xlDown
Case "m"
r = wsSum.Cells.Find(What:="Joineryshop", After:=wsSum.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows).Row
wsSum.Range("A" & r).Insert Shift:=xlDown
Case "j"
r = wsSum.Cells.Find(What:="Stair Dept", After:=wsSum.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows).Row
wsSum.Range("A" & r).Insert Shift:=xlDown
Case "st"
r = wsSum.Cells.Find(What:="Polishing Shop", After:=wsSum.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows).Row
wsSum.Range("A" & r).Insert Shift:=xlDown
Case "p"
r = wsSum.Cells.Find(What:="Delivery", After:=wsSum.Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows).Row
wsSum.Range("A" & r).Insert Shift:=xlDown
Case "d"
r = wsSum.Range("A" & wsSum.Rows.Count).End(xlUp).Row + 1
wsSum.Range("A" & r).Insert Shift:=xlDown
End Select
Next c
End If
Next ws
EH:
Application.ScreenUpdating = True
With Err
If .Number <> 0 Then MsgBox "Oops! There is an error! Conduct error checking!"
.Clear
End With
Set c = Nothing
Set ws = Nothing
Set wsSum = Nothing
End Sub
Thanks in advance for any assistance you can offer!