+ Reply to Thread
Results 1 to 5 of 5

Simplify code

Hybrid View

  1. #1
    Forum Contributor KBSH's Avatar
    Join Date
    09-16-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    113

    Simplify code

    Hey

    Is it possible to simplify this code:
    Do While ActiveCell.Value = "O" Or ActiveCell.Value = "T" Or ActiveCell.Value = "A"
                If ActiveCell.Value = "O" Or ActiveCell.Value = "T" Or ActiveCell.Value = "A" Then
                ActiveCell.Offset(1, 0).Select
                Else: Exit Sub
                End If
            Loop
    I want to make an efficient (fast) code, but this looks terrible. ....any suggestions?
    I'm mediocre with VBA, but getting there

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,445

    Re: Simplify code

    Hi KBSH,

    Instead of
    ActiveCell.Value = "O" Or ActiveCell.Value = "T" Or ActiveCell.Value = "A"
    try
    InStr("OTA", ActiveCell.Value) > 0
    See if that makes more sense and works better for you.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor KBSH's Avatar
    Join Date
    09-16-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    113

    Re: Simplify code

    I don't know the code InStr(), but found out that it worked, so thanks. I did actually hope that it would be more something like Activecell.value = OTA

    The thing that I actually ment is that I have to declare twice that I'm looking for characters like "A" "T" and "O"
    Do While ActiveCell.Value = "O" Or ActiveCell.Value = "T" Or ActiveCell.Value = "A"
                If ActiveCell.Value = "O" Or ActiveCell.Value = "T" Or ActiveCell.Value = "A" Then
    Can't this be done with just one line?
    Last edited by KBSH; 03-05-2016 at 03:12 PM.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Simplify code

    I tried using Instr but for some reason I was getting errors so I decided to use match.

    
    Sub Macro1()
    
    10  If Not IsError(Application.Match(ActiveCell.Text, Array("O", "A", "T"))) Then ActiveCell.Offset(1, 0).Select: GoTo 10:
    
    End Sub
    Last edited by mehmetcik; 03-05-2016 at 03:21 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  5. #5
    Forum Contributor KBSH's Avatar
    Join Date
    09-16-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    113

    Re: Simplify code

    Thanks mehmetcik. I didn't know that you can work with numbers in front of your code and refer to those numbers. Very useful

+ 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. [SOLVED] simplify vba code
    By wyldjokre69 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2014, 10:01 AM
  2. How to simplify code?
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2013, 07:30 AM
  3. [SOLVED] Simplify VBA Code
    By Sky188 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2012, 02:31 PM
  4. Simplify my Code
    By wrathastorm in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 04-26-2012, 02:23 PM
  5. simplify code
    By double a enterprises in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2010, 05:42 AM
  6. hi can anyone simplify this old bit of code
    By khalid79m in forum Excel General
    Replies: 3
    Last Post: 12-28-2006, 01:04 PM
  7. Simplify this code
    By Scott in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2006, 12:00 AM

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