Extracting cells with text from one range and copying them to another range on a different sheet while removing blank cells

divineld

New Member
Joined
Jan 4, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I'm trying to extract cells with text from one range and copy them to another range on a different sheet. For example, I have text in some cells that range from G12:G25. Many of the cells are blank, so I'm looking for something that will take the cells that do have text and copy them to another range (E5:E14) on another worksheet while removing the blank cells. Any tips would be greatly appreciated. Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Could you provide a sample of your data using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform? There's a number of different ways you could do this, but difficult to demonstrate without actual data.
 
Upvote 0
Here's some options for you to consider - 1 x formula or 2 x VBA (put in standard modules).
Book1
G
11
12text
13text
14
15text
16text
17text
18
19text
20text
21text
22
23text
24text
25
26
Sheet1


Book1
E
5text
6text
7text
8text
9text
10text
11text
12text
13text
14text
15
Sheet2
Cell Formulas
RangeFormula
E5:E14E5=FILTER(Sheet1!G12:G25,Sheet1!G12:G25<>"")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Sheet1!_FilterDatabase=Sheet1!$G$12:$G$25E5


VBA Code:
Option Explicit
Sub Test_Copy_1()
    'Change the sheet names to suit
    With Worksheets("Sheet1").Range("G12:G25")
        .AutoFilter 1, "<>"
        .Copy Worksheets("Sheet2").Range("E5")
        .AutoFilter
    End With
End Sub

Sub Test_Copy_2()
    Dim c As Range, r As Range
    'Change the sheet names to suit
    For Each c In Worksheets("Sheet1").Range("G12:G25").SpecialCells(xlCellTypeConstants)
        If r Is Nothing Then Set r = c Else Set r = Union(r, c)
    Next c
    r.Copy Worksheets("Sheet2").Range("E5")
End Sub
 
Upvote 0
So, I could share a screenshot at the moment. I would like to take the range illustrated below with the red box (G12:G44) and pull the names into a smaller range onto the "Sheet 1" tab to consolidate.

1704426602248.png


And as an example, copy only the names into the following range located on the "Sheet 1" tab.

1704426673478.png


If you need the actual spreadsheet, then what functions would you recommend for accomplishing this?
 
Upvote 0
I think our posts may have crossed in the aether 😉
Post #3 adjusted for your sheets:
Book1
C
4text
5text
6text
7text
8text
9text
10text
11text
12text
13text
14text
15text
16text
17text
18text
19text
20text
21text
22text
23text
24text
25text
26text
27text
28
Sheet1
Cell Formulas
RangeFormula
C4:C27C4=FILTER('Sample Roster'!G12:G44,'Sample Roster'!G12:G44<>"")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
'Sample Roster'!_FilterDatabase='Sample Roster'!$G$12:$G$25C4


VBA Code:
Option Explicit
Sub Test_Copy_1()
    With Worksheets("Sample Roster").Range("G12:G44")
        .AutoFilter 1, "<>"
        .Copy Worksheets("Sheet1").Range("C4")
        .AutoFilter
    End With
End Sub

Sub Test_Copy_2()
    Dim c As Range, r As Range
    For Each c In Worksheets("Sample Roster").Range("G12:G44").SpecialCells(xlCellTypeConstants)
        If r Is Nothing Then Set r = c Else Set r = Union(r, c)
    Next c
    r.Copy Worksheets("Sheet1").Range("C4")
End Sub
 
Upvote 0
Solution
Glad to help & welcome to the Forum! (y) :)
Just out of interest, which option did you go with?
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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