+ Reply to Thread
Results 1 to 2 of 2

Error Message Box Help: URGENT!!!

  1. #1
    Registered User
    Join Date
    12-04-2015
    Location
    N/A
    MS-Off Ver
    2013
    Posts
    1

    Exclamation Error Message Box Help: URGENT!!!

    I am making a program that compares two companies and it contains 500 lines of data. I want a message box to appear when the user types an invalid name but the problem is that the error message box comes up 500 times when I need it to come up once. Can anyone help??

    Sub FindCompany()

    Dim companyname As String
    Dim finalrow As Integer
    Dim i As Integer

    Sheets("CompanyRatings").Activate
    companyname = InputBox("Enter the Company Name :")
    finalrow = Sheets("CompanyRatings").Range("A1000").End(xlUp).Row

    For i = 2 To finalrow
    If Cells(i,1) = companyname Then
    Range(Cells(i, 1), Cells(i, 9)).Copy
    Sheets("FrontPage").Activate
    Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
    ActiveSheet.Paste

    ElseIf Cells(i,1) <> companyname Then
    result = MsgBox("Invalid Input", vbOKOnly, "Error Encountered")



    End If
    Next i

    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,091

    Re: Error Message Box Help: URGENT!!!

    Some pointers:

    1. Don't put URGENT, even it is. For you maybe, but the forum is manned by volunteers and they help when they can, and it's usually pretty quick. However, they may be put off by "URGENT"
    2. When you post code excerpts, please use Code Tags, as per the forum rules.
    3. It is generally helpful to post a sample workbook so the problem can be seen in context and solutions tested.

    On a more positive note, instead of using the MsgBox in the loop, set a boolean flag if the condition is met. Then, at the end,check the flag and only then display a message.

    As you activate Sheets("FrontPage"), I'm thinking the code will start to fail straight away because you'll be processing rows on the wrong worksheet. Can't test it, no data.

    Ideally, you should avoid selecting anything. You don't need to in the great majority of cases.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-20-2014, 05:33 PM
  2. Replies: 6
    Last Post: 02-22-2014, 10:00 AM
  3. An error message on open - a totally blank VBA message box
    By Mr_Tigas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2013, 11:29 AM
  4. [SOLVED] replace VBA run-time error message with custom message
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-14-2006, 11:05 AM
  5. [SOLVED] Urgent- Help ! (Message 'Calculate' Appears)
    By Steve C. in forum Excel General
    Replies: 2
    Last Post: 08-16-2005, 09:05 PM
  6. [SOLVED] Drillthrough MDX ERROR(Error.Number:-21467259) ?(urgent question)
    By Microlong in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2005, 10:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1