possible to copy filtered data into one cell?

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
I have filtered data

wb1.Sheets(1).Range("F2:F" & Cells(Rows.Count, "F").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy


and want to copy it to a single cell on the target worksheet

wb.Sheets(1).Range("W" & i).PasteSpecial Paste:=xlPasteValues


I thought this would do it, but the cells are copied to as many cells as selected on the target when completed.


Its it possible to copy all the filtered data to one cell?

Thanks

 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I don't think you can copy multiple cells into one single cell.
You would need to do something like loop through the multiple cells that you want to copy form, and write the results to a single VBA variable, then populate the single destination cell with the value of that variable.
 
Upvote 0
Hi @Danny54, If this is what you need, I hope the following example helps you:

Code:
Sub copy_into_one_cell()
  Dim wb1 As Workbook, wb As Workbook, c As Range, s As String, sep As Variant
  Set wb1 = ThisWorkbook
  Set wb = Workbooks("book2.xlsx")
  sep = "," [COLOR=#008000]'could be "|" or " " or chr(10) or vbtab[/COLOR]
  For Each c In wb1.Sheets(1).Range("F2", wb1.Sheets(1).Range("F" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
    s = s & c & sep
  Next
  If s <> "" Then s = Left(s, Len(s) - 1)
  wb.Sheets(1).Range("W" & 1).Value = s
End Sub
 
Upvote 0
Dante's code does what I was talking about, looping through the range, writing the matching results to a variable, and populating your destination cell with that variable.

If that does not give you what you want, please explain exactly what is in these cells, and what you want the final result to look like.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,217,367
Messages
6,136,148
Members
449,994
Latest member
Rocky Mountain High

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