VBA: Concatenate cells and save as variable

yits05

Board Regular
Joined
Jul 17, 2020
Messages
56
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I was hoping to get some assistance with a VBA problem I am trying to solve. I need a script that combines the contents of cells B2-E2, and saves them as a variable in VBA that I can then manipulate further. Combined, the cells contains greater than 50,000 characters, which is why I cannot concatenate them in the spreadsheet and then assign the cell value as a variable, without losing part of the combined string.

Much appreciated!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Possibly this.

VBA Code:
Sub StrConcatTest()
    Dim CellRange As Range, R As Range, ResultStr As String
    
    With ActiveSheet
        Set CellRange = .Range("B2:E2")
        For Each R In CellRange
            ResultStr = ResultStr & CStr(R.Value)
        Next R
    End With

    MsgBox "ResultStr contains " & Format(Len(ResultStr), "0,000") & " characters", vbOKOnly Or vbInformation, Application.Name
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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