+ Reply to Thread
Results 1 to 7 of 7

[Urgent/Simple] I have a defined function and a defined range of cells. How do I do =MyFun

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    19

    [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =MyFun

    Here is what I have:

    Dim Rngx2 As Range
    Set Rngx2 = Sheets("Sheet2").Range("A1:A" & Range("A1").End(xlDown).Row)
    Sheets("Sheet1").Range("A3").Formula = "=MyConcat(Rngx2)"
    I want to use =MyFunct for that rng. How do I do that?

    Something like... =MyFunct(rng) ... but it won't work.

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

    Re: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Perhaps.
    Dim Rngx2 As Range
    Set Rngx2 = Sheets("Sheet2").Range("A1:A" & Range("A1").End(xlDown).Row)
    Sheets("Sheet1").Range("A3").Formula = "=MyConcat(" & Rngx2.Address(External:=True & ")"
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-11-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    19

    Re: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Quote Originally Posted by Norie View Post
    Perhaps.
    Dim Rngx2 As Range
    Set Rngx2 = Sheets("Sheet2").Range("A1:A" & Range("A1").End(xlDown).Row)
    Sheets("Sheet1").Range("A3").Formula = "=MyConcat(" & Rngx2.Address(External:=True & ")"
    Says there is a syntax error on the last line. Any idea?

  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: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Oops, slight typo.
    Dim Rngx2 As Range
    Set Rngx2 = Sheets("Sheet2").Range("A1:A" & Range("A1").End(xlDown).Row)
    Sheets("Sheet1").Range("A3").Formula = "=MyConcat(" & Rngx2.Address(External:=True) & ")"

  5. #5
    Registered User
    Join Date
    01-11-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    19

    Re: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Woohoo, that did it! Last simple question. How do I remove the last chr(10) from the concatenated cell? I only ask because my function looks like this:

    Function MyConcat(myRange As Range) As String
    
        Dim cell As Range
        For Each cell In myRange
            MyConcat = MyConcat & cell.Value & Chr(10)
        Next cell
        
    End Function
    It seems to add an extra chr(10) or two after the function concatantes the range.
    Last edited by excelfriend1; 03-29-2016 at 05:54 PM.

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,345

    Re: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Not sure exactly what you want but try one of these

    Function MyConcat(myRange As Range) As String
    
        Dim cell As Range
        For Each cell In myRange
            MyConcat = MyConcat & cell.Value & Chr(10)
        Next cell
      MyConcat = left(MyConcat,len(MyConcat)-1)  
    
    End Function
    
    
    
    
    Function MyConcat(myRange As Range) As String
    
    Dim cell As Range
    For Each cell In myRange
    if MyConcat = "" then
    MyConcat = cell.Value
    else        
    if cell.Value = "" then
    else
    MyConcat = MyConcat & Chr(10) & cell.Value
    end if    
    end if
    Next cell
    End Function

  7. #7
    Registered User
    Join Date
    01-11-2016
    Location
    USA
    MS-Off Ver
    2010
    Posts
    19

    Re: [Urgent/Simple] I have a defined function and a defined range of cells. How do I do =M

    Quote Originally Posted by scottiex View Post
    Not sure exactly what you want but try one of these

    Function MyConcat(myRange As Range) As String
    
        Dim cell As Range
        For Each cell In myRange
            MyConcat = MyConcat & cell.Value & Chr(10)
        Next cell
      MyConcat = left(MyConcat,len(MyConcat)-1)  
    
    End Function
    
    
    
    
    Function MyConcat(myRange As Range) As String
    
    Dim cell As Range
    For Each cell In myRange
    if MyConcat = "" then
    MyConcat = cell.Value
    else        
    if cell.Value = "" then
    else
    MyConcat = MyConcat & Chr(10) & cell.Value
    end if    
    end if
    Next cell
    End Function
    SECOND ONE DID IT. Love you. Thanks!

+ 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] If word entered not in defined name range, copy & paste it to bottom of defined name range
    By Butcher1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2014, 01:08 PM
  2. [SOLVED] Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax
    By winch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 11:02 AM
  3. [SOLVED] Run Time 1004 - App Defined or Object defined error with String defined path structure
    By sarails in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2012, 09:38 PM
  4. Replies: 3
    Last Post: 07-24-2006, 08:20 PM
  5. Application-Defined or Object-Defined Error on simple code
    By Fid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2005, 04:05 PM
  6. [SOLVED] User-Defined Function to Determine Content of Cells in a Range
    By RBohannon in forum Excel General
    Replies: 2
    Last Post: 06-02-2005, 12:05 PM
  7. [SOLVED] Application-Defined or Object-Defined Error on simple code
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2005, 05:06 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