VBA, Ignore blank cells when concatenating data from one worksheet to another

Status
Not open for further replies.

Pitmo

New Member
Joined
Jan 31, 2017
Messages
11
Hello,

VBA below pulls text from multiple worksheets and places in one cell in master worksheet. However I need to ignore the blank returns as they are creating lots of whitespace in the 'Survey Results' worksheet.

Can anyone help with this?

Code:
Sub TextMerge()Dim x1 As Long
Dim x2 As Long
Dim s As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
s = 0
For Each ws In ActiveWorkbook.Sheets
s = s + 1
If ws.Name = "Start" Then x1 = s + 1
If ws.Name = "End" Then x2 = s - 1
Next
For i = x1 To x2


Sheets("Survey Results").Cells(5, 5).Value = Sheets("Survey Results").Cells(5, 5).Value & vbCrLf & Sheets(i).Cells(4, 5).Value


Next
Sheets("Survey Results").Cells(5, 5).Value = WorksheetFunction.Replace(Sheets("Survey Results").Cells(5, 5).Value, 1, 1, "")




For i = x1 To x2


Sheets("Survey Results").Cells(6, 5).Value = Sheets("Survey Results").Cells(6, 5).Value & vbCrLf & Sheets(i).Cells(5, 5).Value


Next
Sheets("Survey Results").Cells(6, 5).Value = WorksheetFunction.Replace(Sheets("Survey Results").Cells(6, 5).Value, 1, 1, "")


For i = x1 To x2


Sheets("Survey Results").Cells(7, 5).Value = Sheets("Survey Results").Cells(7, 5).Value & vbCrLf & Sheets(i).Cells(6, 5).Value


Next
Sheets("Survey Results").Cells(7, 5).Value = WorksheetFunction.Replace(Sheets("Survey Results").Cells(7, 5).Value, 1, 1, "")


For i = x1 To x2


Sheets("Survey Results").Cells(8, 5).Value = Sheets("Survey Results").Cells(8, 5).Value & vbCrLf & Sheets(i).Cells(7, 5).Value


Next
Sheets("Survey Results").Cells(8, 5).Value = WorksheetFunction.Replace(Sheets("Survey Results").Cells(8, 5).Value, 1, 1, "")


  
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub

Thanks, Pitmo
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Duplicate: https://www.mrexcel.com/forum/excel...-single-cells-variable-number-worksheets.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. Per forum rules, posts of a duplicate nature will be locked or deleted (rule #12 here: Forum Rules).

If you do not receive a response, you can "bump" it by replying to it again, though we advise you not to bump a thread more than once a day.
 
Last edited:
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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