Issue in Concatenate Function

Gaurangg

Board Regular
Joined
Aug 6, 2015
Messages
134
Hi Friends,

I need a help in a scenario. I am applying a function to concatenate a column range. However when I run the main code, it stucks in that function instead of running the main code.

I have add code of concatenate function in a module and add another main code to run in another module. In main code, there is no any path given to go to function code still it doesnot go further and stucks into Function when I am testing by pressing F8.

Please suggest with the required correction. I am mentioning both the code below.

Concatenate function code:
Code:
Function CONCATENATEMULTIPLE(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
 Result = Result & Cell.Value & Separator
Next Cell
CONCATENATEMULTIPLE = Left(Result, Len(Result) - 1)
End Function

Main Code
Code:
Sub AssignCourse()
'
'
'Opening Unipart File
Dim TWK As Workbook
Dim Mypath As String
Dim namfil As String

Set TWK = ThisWorkbook

    Mypath = TWK.Sheets("Main").Range("CA1").Value
    namfil = TWK.Sheets("Main").Range("CB1").Value
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    ThisWorkbook.Activate
    Sheet1.Select
    Sheet1.Unprotect Password:="Vodafone"
    
        
    Sheet1.Range("BO2:BW100000").ClearContents
        
    Sheet1.Select
    Mypath = Sheet1.Range("CA1").Value
    Workbooks.Open Filename:=Mypath
    NwFile = ActiveWorkbook.Name
    shname = ActiveSheet.Name
   
    Sheets(shname).Name = "Data"
    Sheets("Data").Activate
    ActiveSheet.Select
    Columns("A:Z").ColumnWidth = 20
    Range("A2").Select
    Range("A2:A65536").Select
    Selection.Copy
    
    ThisWorkbook.Activate
    Sheet1.Select
    Range("BQ2").Select
    
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
     Windows(NwFile).Close
    
    ThisWorkbook.Activate
    Sheet1.Select
    
    Range("BU2").Select
    
    MYRW = Sheet1.Range("BQ1048576").End(xlUp).Row
    MARW = Sheet1.Range("BQ1048576").End(xlUp).Row
    
    Range("BP2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[1],Database!C[-67]:C[-65],3,0),"""")"
    Range("BO2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(RC[1]="""",R[1]C[1]=""""),"""",IF(AND(RC[1]<>"""",R[1]C[1]=""""),RC[1],RC[1]&""; ""))"
    Range("BR2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],Database!C[-69]:C[-67],3,0),"""")"
    Range("BW2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
    Range("BU2").Select
    ActiveCell.FormulaR1C1 = "=R2C62"
    
    Range("BS2").Value = Range("L13").Value
    Range("BB1").Value = Range("L13").Value
    Range("BV2").Value = Range("L15").Value
    Range("BT2").Select
    ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Database!C9:C10,2,0),"""")"
    
    Range("BO2").Select
    Selection.AutoFill Destination:=Range("BO2:BO" & MYRW)
    Range("BP2").Select
    Selection.AutoFill Destination:=Range("BP2:BP" & MYRW)
    
    
    Range("BR2").Select
    Selection.AutoFill Destination:=Range("BR2:BR" & MYRW)
    Range("BS2").Select
    Selection.AutoFill Destination:=Range("BS2:BS" & MYRW)
    Range("BT2").Select
    Selection.AutoFill Destination:=Range("BT2:BT" & MYRW)
    Range("BU2").Select
    Selection.AutoFill Destination:=Range("BU2:BU" & MYRW)
    Range("BV2").Select
    Selection.AutoFill Destination:=Range("BV2:BV" & MYRW)
    Range("BW2").Select
    Selection.AutoFill Destination:=Range("BW2:BW" & MYRW)
    
    
    Range("BO2:BW" & MYRW).Copy
    Range("BO2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("BQ2:BW" & MYRW).Copy
    Sheet2.Select
    Range("A" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheet1.Select
    
    'FrmValue = InputBox("Enter the Sender Email ID ", "Vodafone University Course Allocation", 1)
    'Sheet1.Range("BB4") = FrmValue
    
    Range("BB4").Select
    ActiveCell.FormulaR1C1 = "=CONCATENATEMULTIPLE(R[-1]C[13]:R[1997]C[13],"" "")"
    Range("BB4").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Call Email_Syndicate
    
    
      
End Sub
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Re: Issue in Cancatenate Function

As you are turning BB4 into a value why not just do this
Code:
Sub AssignCourse()
'
'
'Opening Unipart File
Dim TWK As Workbook
Dim Mypath As String
Dim namfil As String

Set TWK = ThisWorkbook

    Mypath = TWK.Sheets("Main").Range("CA1").Value
    namfil = TWK.Sheets("Main").Range("CB1").Value
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    ThisWorkbook.Activate
    Sheet1.Select
    Sheet1.Unprotect Password:="Vodafone"


    Sheet1.Range("BO2:BW100000").ClearContents

    Sheet1.Select
    Mypath = Sheet1.Range("CA1").Value
    Workbooks.Open FileName:=Mypath
    NwFile = ActiveWorkbook.name
    shname = ActiveSheet.name

    Sheets(shname).name = "Data"
    Sheets("Data").Activate
    ActiveSheet.Select
    Columns("A:Z").ColumnWidth = 20
    Range("A2").Select
    Range("A2:A65536").Select
    Selection.Copy

    ThisWorkbook.Activate
    Sheet1.Select
    Range("BQ2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
     Windows(NwFile).Close

    ThisWorkbook.Activate
    Sheet1.Select

    Range("BU2").Select

    MYRW = Sheet1.Range("BQ1048576").End(xlUp).row
    MARW = Sheet1.Range("BQ1048576").End(xlUp).row

    Range("BP2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[1],Database!C[-67]:C[-65],3,0),"""")"
    Range("BO2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(RC[1]="""",R[1]C[1]=""""),"""",IF(AND(RC[1]<>"""",R[1]C[1]=""""),RC[1],RC[1]&""; ""))"
    Range("BR2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],Database!C[-69]:C[-67],3,0),"""")"
    Range("BW2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
    Range("BU2").Select
    ActiveCell.FormulaR1C1 = "=R2C62"

    Range("BS2").Value = Range("L13").Value
    Range("BB1").Value = Range("L13").Value
    Range("BV2").Value = Range("L15").Value
    Range("BT2").Select
    ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Database!C9:C10,2,0),"""")"

    Range("BO2").Select
    Selection.AutoFill Destination:=Range("BO2:BO" & MYRW)
    Range("BP2").Select
    Selection.AutoFill Destination:=Range("BP2:BP" & MYRW)


    Range("BR2").Select
    Selection.AutoFill Destination:=Range("BR2:BR" & MYRW)
    Range("BS2").Select
    Selection.AutoFill Destination:=Range("BS2:BS" & MYRW)
    Range("BT2").Select
    Selection.AutoFill Destination:=Range("BT2:BT" & MYRW)
    Range("BU2").Select
    Selection.AutoFill Destination:=Range("BU2:BU" & MYRW)
    Range("BV2").Select
    Selection.AutoFill Destination:=Range("BV2:BV" & MYRW)
    Range("BW2").Select
    Selection.AutoFill Destination:=Range("BW2:BW" & MYRW)


    Range("BO2:BW" & MYRW).Copy
    Range("BO2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("BQ2:BW" & MYRW).Copy
    Sheet2.Select
    Range("A" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheet1.Select

    'FrmValue = InputBox("Enter the Sender Email ID ", "Vodafone University Course Allocation", 1)
    'Sheet1.Range("BB4") = FrmValue
    
    Range("BB4").Value = CONCATENATEMULTIPLE(Range("BO3:BO2001"), " ")
    
    Call Email_Syndicate
    
    
      
End Sub
 
Upvote 0
Re: Issue in Cancatenate Function

Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top