+ Reply to Thread
Results 1 to 6 of 6

Using the Find Function inside the Right function in macro

  1. #1
    Registered User
    Join Date
    05-22-2013
    Location
    Tupelo, MS
    MS-Off Ver
    Excel 2013
    Posts
    3

    Using the Find Function inside the Right function in macro

    I have a column with data that I am wanting to clean up and place into a new column.

    I begin by finding the last row with data and setting that to LR
    Then I create a new column and add a value for a header

    I want to to use the right function in conjunction with the Find function to look for a specific string and return everything to the right of that string as a value I am placing in a newly created column.

    I am getting a Type mismatch error 13.

    I have narrowed down, by removing pieces of code, that the issue is with the Find portion of the code in this line.

    Below is my stab at performing this task. Any help would be much appreciated. I am new to vba and learning as I go.

    Sub cleanUpFileName()

    Dim LR As Long, i As Long

    LR = Range("C" & Rows.Count).End(xlUp).Row
    Worksheets(1).Columns(4).Insert shift:=xlRight
    Worksheets(1).Range("D1").Value = "test_file"

    For i = 2 To LR
    With Range("C" & i)
    Select Case .Value
    Case "": .Offset(, 1).Value = "Null"
    'Case Else: .Offset(, 1).Value = Right(.Value, Len(.Value) - .Find("testfiles/", (.Value)) - 9)
    Case Else: .Offset(, 1).Value = Right(.Value, Len(.Value) - .Find(What:="testfiles/", LookIn:=(.Value), MatchCase:=False))
    End Select
    End With
    Next i

    End Sub



    Thanks in advance!
    Last edited by namruht; 08-27-2013 at 12:55 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,621

    Re: Using the Find Function inside the Right function in macro

    Please Login or Register  to view this content.
    , not LookIn:=(.Value)
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    05-22-2013
    Location
    Tupelo, MS
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Using the Find Function inside the Right function in macro

    I got the same error when using xlValues instead of .Value.

    Could this be a problem with the trying to return a string and assign it to .Value?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using the Find Function inside the Right function in macro

    If you are trying to find the position of one string within another have a look at InStr.
    Please Login or Register  to view this content.
    You might also want to look at Mid, Left and Split.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    05-22-2013
    Location
    Tupelo, MS
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Using the Find Function inside the Right function in macro

    Thanks Norie! Switching to the Instr function solved my issue.
    Can you give me an explanation so that I understand why that worked vs. the Find function?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using the Find Function inside the Right function in macro

    Find is used to find things, eg values, in a range, not within a string.

    This would have returned the value in the range where the search term was found.
    Please Login or Register  to view this content.
    That value would most likely be text, and since the second argument of Right should be a number you would get a type mismatch error.

+ 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: 01-19-2013, 01:35 PM
  2. [SOLVED] Using ROW function inside of both an Indirect and Index function returns #VALUE
    By xandermacleod in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-11-2012, 06:22 PM
  3. Function inside Macro that move a range rows if cells are used
    By oguilamo in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 08-29-2012, 11:51 PM
  4. Macro does not function inside a list control
    By Stephen Giles in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2006, 03:40 PM
  5. HELP NEEDED FOR IF Function Inside a Macro
    By Sandi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-01-2006, 11:20 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