ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Ive now finished with my project & the below is the final code.
Can it be simplfied to run faster / smoother.
Thanks
Can it be simplfied to run faster / smoother.
Thanks
VBA Code:
Private Sub AddKeyToTableList_Click()
Dim response As Integer
Dim oNewRow As ListRow
' ADD NEW KEY TYPE TO TABLE
With Sheets("INFO").ListObjects("Table38")
If IsError(Application.Match(Me.TextBox3.Value, .ListColumns(1).DataBodyRange.Value, 0)) Then
Set oNewRow = .ListRows.Add
oNewRow.Range.Cells(1) = Me.TextBox3.Value
.Sort.SortFields.Clear
.Sort.SortFields.Add KEY:=.ListColumns(1).Range, SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
With .Sort
.Header = xlYes
.Apply
End With
Application.Goto (.HeaderRowRange.Cells(1))
Sheets("INV").Select 'RELOAD INV WORKSHEET
Me.ComboBox1.Value = Me.TextBox3.Value
WillContinueSoon.Show
Else
MsgBox Me.TextBox3.Value & " KEY TYPE ALRADY EXISTS", vbInformation, "KEY TYPE EXISTS MESSAGE"
End If
End With
ThisWorkbook.Worksheets("INV").Range("G22") = Me.TextBox1.Text ' BITING SENT TO WORKSHEET CELL G22
ThisWorkbook.Worksheets("INV").Range("G23") = Me.ComboBox1.Text ' KEY TYPE USED SENT TO WORKSHEET CELL G23
Dim wb As Workbook
Set wb = Workbooks.Open(fileName:="C:\Users\Ian\Desktop\REMOTES ETC\DR\EXCEL WORKSHEETS\MOTORCYCLES.xlsm")
Workbooks("MOTORCYCLES.xlsm").Sheets("INVOICES").Activate
ActiveSheet.Rows("3").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Workbooks("DR.xlsm").Sheets("INV").Range("G13").Copy ' CUSTOMERS NAME
wb.Sheets("INVOICES").Range("A3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("L16").Copy ' FRAME NUMBER
wb.Sheets("INVOICES").Range("B3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("L15").Copy ' REGISTRATION
wb.Sheets("INVOICES").Range("C3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("G22").Copy ' BITING
wb.Sheets("INVOICES").Range("D3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("G23").Copy ' TYPE OF KEY
wb.Sheets("INVOICES").Range("E3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("L13").Copy ' DATE OF JOB
wb.Sheets("INVOICES").Range("F3").PasteSpecial xlPasteValues
Workbooks("DR.xlsm").Sheets("INV").Range("L4").Copy ' INVOICE NUMBER
wb.Sheets("INVOICES").Range("G3").PasteSpecial xlPasteValues
Dim x As Long
Application.ScreenUpdating = False
With Sheets("INVOICES")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.count, 2).End(xlUp).Row
.Range("A1:G" & x).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess
End With
ActiveWorkbook.Save
Application.ScreenUpdating = True
Sheets("INVOICES").Range("A3").Select
wb.Close True
Application.CutCopyMode = False
Unload Me
With ActiveSheet
Range("D1").Select
End With
End Sub