+ Reply to Thread
Results 1 to 4 of 4

Insert Function with Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-16-2015
    Location
    Knoxville, TN
    MS-Off Ver
    2013
    Posts
    22

    Insert Function with Macro

    Hello all,

    I use a certain function enough on my excel sheets, I no longer want to copy and paste but to just use a macro to insert my function. The original data is formatted like this:

    FirstName LastName
    FirstName LastName
    FirstName LastName

    The function I am using is:
    =CONCATENATE(MID(A1,FIND(" ",A1)+1,256),", ",LEFT(A1,(FIND(" ",A1,1)-1)))

    The function turns my original data into:

    LastName, FirstName
    LastName, FirstName
    LastName, FirstName

    I would like to come up with a simple macro that runs a for each loop that inserts the function in column B based on column A. If you know of an easier way, I am all ears!

    Thank you.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Insert Function with Macro

    Hi lonesoac0,
    try it
    Sub ttt()
    Dim x, i&, sp
    With Range("A1", Cells(Rows.Count, 1).End(xlUp))
        x = .Value
        For i = 1 To UBound(x)
            sp = Split(Replace(x(i, 1), ",", ""))
            x(i, 1) = sp(1) & ", " & sp(0)
        Next i
        .Value = x
    End With
    End Sub

  3. #3
    Registered User
    Join Date
    09-16-2015
    Location
    Knoxville, TN
    MS-Off Ver
    2013
    Posts
    22

    Re: Insert Function with Macro

    I ran the code you gave me and I got the error code of: "Run-time error '13' Type Mismatch". I ran the debugger and it highlighted: "For i = 1 To UBound(x)"

  4. #4
    Registered User
    Join Date
    09-16-2015
    Location
    Knoxville, TN
    MS-Off Ver
    2013
    Posts
    22

    Re: Insert Function with Macro

    Ok, so I decided to play with it a little more and I inserted two FirstName LastName and it worked just fine. Gracias.

+ 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] Macro to insert sum function to inconsistent data
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 09:22 PM
  2. [SOLVED] Insert array function in macro
    By b_rianv in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-28-2014, 04:58 PM
  3. How to modify macro to insert a colored row with a date function??
    By Jason.eschberger in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-11-2013, 03:40 PM
  4. how to insert in macro - sheetname as function
    By phoenixwright in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2013, 06:39 PM
  5. Autmation Error with Macro insert function
    By amirah_almu7aka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2012, 07:26 AM
  6. [SOLVED] Insert macro in IF Function
    By blade in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-30-2006, 05:10 PM
  7. How can I insert a run macro command in the IF function?
    By emil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2006, 10:10 AM

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