+ Reply to Thread
Results 1 to 6 of 6

if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

Hybrid View

a8015945 if Range("A1") = "Mike" Then... 08-30-2013, 09:49 AM
BigBas Re: if Range("A1") = "Mike"... 08-30-2013, 09:53 AM
Winon Re: if Range("A1") = "Mike"... 08-30-2013, 09:55 AM
Winon Re: if Range("A1") = "Mike"... 08-30-2013, 09:59 AM
a8015945 Re: if Range("A1") = "Mike"... 08-30-2013, 10:01 AM
BigBas Re: if Range("A1") = "Mike"... 08-30-2013, 10:08 AM
  1. #1
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    Hi

    I have a bit of an issue.

    I have a long list of if statements that are basically as follows:

    if Range("A1") = "Mike" Then Range("A1") = "michael"
    if Range("A1") = "Matt" Then Range("A1") = "matthew"
    etc

    This list has 40+ names that are defined as something (ie Mike)(taken from external data) but need to be something else (ie michael)

    What I want to do is the following:
    if Range("A1") = "Mike" Then Range("A1") = "michael" Then ExitSub
    to avoid the macro going through all 40+ if statements everytime

    My current get around is the following

    If Range("A1") = "Mike" Then
        Range("A1") = "michael"
        Exit Sub
    End If
    but it takes up huge amounts of space in the code and probably isnt the most effiecient way of doing it. Plus it doesnt look very good

    Does anyone know a simple work around?

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    Something like the following, incorporated into your sheet?

    Sub haha()
        Select Case Range("A1").Value
            Case "Mike": Range("A1").Value = "michael"
            Case "Matt": Range("A1").Value = "matthew"
        End Select
            
            
    End Sub

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    Hello a8015945,

    The first thing that comes to my mind is to use a helper Column with an Index Match formula, and then a Macro to copy and paste the value to A1 etc.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    The solution BigBas came up with, will also work great! Just enter all forty or so names within the Case Select, each with Case "Fred"....etc.

    @ BigBas,

    Nice one!

  5. #5
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    Cheers BigBas

    Works perfectly

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub

    For the record, I do want to state that this seems like an overly complicated bit of code (over 40 names, each tied to a specific cell), and it would seem more logical to store the information in a "database sheet" of sorts. If you want help with implementation, let us know and we will do our best to help.

+ 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: 3
    Last Post: 02-16-2011, 02:55 PM
  2. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  3. Replies: 5
    Last Post: 06-26-2006, 09:23 PM
  4. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  5. [SOLVED] use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 PM

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