Consulting

Results 1 to 5 of 5

Thread: Make the range dynamic

  1. #1

    Make the range dynamic

    Hello

    I have the following code:
    ActiveCell.FormulaR1C1 = "=TEXTJOIN("" "",TRUE,R[1]C:R[8]C)"
        ActiveCell.Select
        ActiveCell.Copy
        ActiveCell.Offset(1, 0).Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        ActiveCell.Offset(-1, 0).Range("A1").Select
        Selection.ClearContents
        ActiveCell.Offset(2, 0).Range("A1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.ClearContents
    End Sub
    I need the range for the function TEXTJOIN to be dynamic. How do I do that?
    Last edited by Aussiebear; 11-22-2016 at 05:31 PM. Reason: Added code tags

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Ole Kristen,

    Currently, you are using the active cell and concatenating the next eight rows that are not blank. What do you want to change?
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    Instead of taking the next eigth it should take the number of cells after eachother that contain samething. So, if there are ten or seven cells after eachother the function concate them and not only eigth of them.

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    Sub test()
        Dim r As Range
        Dim s As String
        
        With ActiveCell
            set r = Range(.Offset(1), .End(xlDown))
            s = TEXTJOIN(" ", True, r)
            r.ClearContents
            .Offset(1).Value = s
        End With
        
    End Sub

  5. #5
    VBAX Regular
    Joined
    Nov 2016
    Posts
    13
    Location
    mana - Unfortunately TextJoin is not available directly to VBA
    perhaps replace
    s = TEXTJOIN(" ", True, r)
    EITHER with
    s = WorksheetFunction.TextJoin(" ", True, r)
    OR else with the 2 lines
    s = "=TEXTJOIN("" "",TRUE," & r.Address(0, 0) & ")"
    s = Evaluate(s)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •