Need help speeding up my Macro

Smilechild793

New Member
Joined
Apr 27, 2017
Messages
20
Every time I run my macro, it takes about 1 min to execute. How can I fix this?

Code:
Sub Button1_Click()Dim myRange As Range
Set myRange = ThisWorkbook.Worksheets("Data Entry").Range("Data")
Dim lastrow As Long
Dim whichsheet As String
whichsheet = InputBox("In which sheet do you wish to enter data?", "Sheet Number")
    If whichsheet = "" Then
    MsgBox "You didn't specify a sheet!"
    Exit Sub
    End If


lastrow = Sheets(whichsheet).Cells(Rows.Count, 1).End(xlUp).Row + 1
With Sheets(whichsheet)


'Add "Input By"
.Cells(lastrow, 1).Value = Sheets("Data Entry").Cells(21, 4).Value


'Add "On Behalf of"
.Cells(lastrow, 2).Value = Sheets("Data Entry").Cells(21, 8).Value


'Add "Date"
.Cells(lastrow, 3).Value = Sheets("Data Entry").Cells(19, 4).Value


'Add "Amount to Expense"
.Cells(lastrow, 9).Value = Sheets("Data Entry").Cells(25, 4).Value


'Add "Vendor"
.Cells(lastrow, 5).Value = Sheets("Data Entry").Cells(27, 4).Value


'Add "Invoice #"
.Cells(lastrow, 6).Value = Sheets("Data Entry").Cells(29, 4).Value


'Add "Cost Category"
.Cells(lastrow, 7).Value = Sheets("Data Entry").Cells(25, 8).Value


'Add "Description"
.Cells(lastrow, 8).Value = Sheets("Data Entry").Cells(27, 8).Value


End With


'Unload Data Entry Form
myRange.ClearContents


Exit Sub
End Sub
 
I note your Input box asks for Sheet Number !....I used sheet name...that may make a difference !!
Also the last Exit Sub is not required.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top