I was trying to make a quick tool today at work to automate some tasks at work but ran into the problem of getting Sun or Function error. I am an absolute newbie in VB and not familiar with the syntax and or language specifics. Could you please help me? Details on what I a trying to do: Basically, I have multiple groups(just 4 cells in each group) that I am trying to copy into single cell. Like this:
Group1: cell1 cell2 cell3 cell4
Group2: . . . Each one of those groups need to be copied into separate cells.
Here is the code:
Public Sub GlobalConcatenation() Dim sourcerange As Range Dim gbegin As Integer Dim gend As Integer gbegin = 2 gend = 5 sourcerange = Sheets("raw_LSToolData").Range(Cells(2, gbegin), Cells(2, gend)) Dim i As Integer For i = 2 To 50 callConcatinateAllCellValuesInRange (sourcerange) sourcerange = Sheets("raw_LSToolData").Range(Cells(2, gbegin + 4), Cells(2, gend + 4)) End Sub Function ConcatinateAllCellValuesInRange(sourcerange As Excel.Range) As String Dim finalValue As String Dim cell As Excel.Range For Each cell In sourcerange.Cells finalValue = finalValue + CStr(cell.Value) Next cell ConcatinateAllCellValuesInRange = finalValue End Function
EDIT: I feel like I also need to specify that the problem shows up in GlobalConcatenation() function and whenever I get the error, "sourcerange" is being highlighted.
EDIT: updated the code - fixed spelling mistake