Announcement

Collapse
No announcement yet.

Compile Error: Variable not defined

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compile Error: Variable not defined



    When I run my UserForm and sned the data to my data collection worksheet (called "Long Trades") I get a message saying "Compile Error: Variable not defined. The problem appears to be with the line NextRow = _ for some reason. Any thoughts?
    Code:
    Private Sub TradeConfirmButton_Click()
    
    '   Make sure number of shares is entered
        If TextShares.Text = "" Then
        MsgBox "You must enter a number of shares"
        End If
            
    '   Make sure price of shares is entered
        If TextPrice.Text = "" Then
        MsgBox "You must enter a share price"
        End If
    
    'Make sure sheet 'Long Trades' is active
        Sheets("Long Trades").Activate
    
    'Determine the next empty row
        NextRow = _
        Application.WorksheetFunction.CountA(Range("A:A")) + 1
        
    'Transfer the Date
        Cells(NextRow, 1) = TextDate.Text
    
    'Transfer the ticker
        Cells(NextRow, 2) = TextTicker.Text
    
    '   Transfer the Company
    Cells(NextRow, 3) = TextCompany.Text
    
    '   Transfer the Number of Shares
    Cells(NextRow, 4) = TextShares.Text
    
    '   Transfer the Price
    Cells(NextRow, 5) = TextPrice.Text
    
    'Transfer Commission Rate
    Cells(NextRow, 6) = TextCommissionRate.Text
    
    'Transfer Commission
    Cells(NextRow, 7) = TextCommission.Text
    
    'Transfer Stamp Duty
    Cells(NextRow, 8) = TextStampDuty.Text
    
    'Transfer Total Cost Local
    Cells(NextRow, 9) = TextTotalCost.Text
    
    'Transfer Country
    Cells(NextRow, 10) = TextCurrency.Text
    
    'Transfer Exchange Rate
    Cells(NextRow, 11) = TextExchangeRate.Text
    
    'Transfer Total Cost USD
    Cells(NextRow, 12) = TextUSDTotal.Text
    
    'Make sure sheet 'Long Trades' is active
    Sheets("Average Prices").Activate
    
    'Transfer the Company
    Range("B4") = TextCompany.Text
        
    'Transfer the Date
    Range("C4") = TextShares.Text
    
    Unload UserForm2
    
    'Make sure sheet 'US Portfolio' is active
    Sheets("US Portfolio").Activate
    Range("A1").Select
    
    End Sub
    Last edited by Jack in the UK; February 6th, 2005, 09:20. Reason: Added Code Tags

  • #2
    Re: Compile Error: Variable not defined

    You need to define it.

    Dim NextRow as Long
    Kind Regards,
    Ivan F Moala From the City of Sails

    http://www.xcelfiles.com

    Comment


    • #3
      Re: Compile Error: Variable not defined

      It works!
      Thanks very much.

      Comment


      • #4


        Re: Compile Error: Variable not defined

        bbromley

        Please can i ask you edit you post with VBA code tags, as this post is solved i will do this for you, please see my sign for teh links if you need help on this.

        Jack

        Comment

        Working...
        X