dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,362
- Office Version
- 365
- 2016
- Platform
- Windows
I have some code that works perfectly. Only issue is that I want to add an autofit feature in. This is my code. WsTrack is a monthly sheet that entries are copied to and I want to autofit columns A:H in each instance of WsTrack at the end of the copy part of my procedure so that it doesn't autofit on every interation, just once at the end.
I get the error when I try and run it, Object doesn't support this property or method.
What is the syntax to do this with autofit?
I get the error when I try and run it, Object doesn't support this property or method.
VBA Code:
With wsTrack
lasttrack = .Cells(Rows.Count, "A").End(xlUp).Row + 1
'this copies the date column in the tblCosting
' tblrow.Range(, 1).Copy
'this pastes it into column A of report tracking file
'.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteFormulasAndNumberFormats
.Range(.Cells(lasttrack, 1), .Cells(lasttrack, 1)) = inarr(i, 1)
'this copies the YP name column in the tblCosting
' tblrow.Range(, 4).Copy
'this pastes it into column B of the report tracking file
out1(1, 1) = inarr(i, 4)
' .Range(.Cells(lasttrack, 2), .Cells(lasttrack, 2)) = inarr(i, 4)
'this copies the YP name column in the tblCosting
' tblrow.Range(, 5).Copy
'this pastes it into column A of report tracking file
out1(1, 2) = inarr(i, 5)
.Range(.Cells(lasttrack, 2), .Cells(lasttrack, 3)) = out1 ' this saves 1 workhseet access
lrTrack = wsTrack.Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
wsTrack.Sort.SortFields.Clear
wsTrack.Sort.SortFields.Add Key:=Range("A2:A" & lrTrack), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
Columns("A:H").Select
Columns("A:H").EntireColumn.AutoFit
With Workbooks(ReportTracking).Worksheets(Combo).Sort
'set range to sort of A3 to AO
.SetRange Range("A1:I" & lrTrack)
.header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
What is the syntax to do this with autofit?
Last edited by a moderator: