Hello everyone I am back with yet another beginner question.
I recently wrote a code in VBA for a button, which copies values from one sheet to another. The first sheet I use to make some custom entry and the destination sheet is like a database with all the entries. This at first worked out quite well but the more entries in the database the slower the script gets.
I was wondering if there is a way to speed up the process or at least provide me with the possibility to change the sheet once I pressed the button and to some other tasks.
My code:
Variable
ws
is the sheet that contains the data and the button.Variable
ws1
is the database location.
Private Sub CommandButton1_Click()
Dim Ticker As String, Nameofcompany As String, Industry As String, Sector As String, Price As String, MC As String, Revenue As String, Valuation As String, Confidence As String, Criteria As String, Watchlist As String, Track As String, Today As String, ExTicker As Range
Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
Set ws = Sheet4
Set ws1 = Sheet3
Set ws2 = Sheet2
ws.Select
Ticker = Range("Ticker")
Set ExTicker = ws1.Range("C5:C500").Find(what:=Ticker, LookIn:=xlValues, lookat:=xlWhole)
If ExTicker Is Nothing Then
Nameofcompany = Range("Name")
Industry = Range("Industry")
Sector = Range("Sector")
Price = Range("Price")
MC = Range("MC")
Revenue = Range("Revenue")
Valuation = Range("Valuation")
Confidence = Range("Confidence")
Criteria = Range("Criteria")
Watchlist = Range("Watchlist")
Track = Range("Track")
Today = Range("O5")
ws1.Select
ws1.Range("C4").Select
If ws1.Range("C4").Offset(1, 0) <> "" Then
ws1.Range("C4").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Ticker
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Nameofcompany
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Industry
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Sector
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Price
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = MC
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Revenue
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Valuation
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Confidence
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Criteria
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Watchlist
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Track
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Today
Else
MsgBox "This company is already in the list"
End If
End Sub