Formula or vba code to copy entire column based on text found in entire cell range

Rahulkr

Board Regular
Joined
Dec 10, 2019
Messages
66
Office Version
  1. 2010
Platform
  1. Windows
Dear All masters, I am having some data like below:- Is there any formula or Vba code to fetch or copy entire column based on text found. Many many thanks in advance.
ColumnABCDEFG
Row 1DaysD1D2D3D4D5D6
Row 2typePH1PH2PH3PH4PH5PH6
Row 3jk
Row 4lm
Row 5
Row 6no
Row 7
Row 808:30 Ande
Row 9
Row 10789pq
Row 1189yy

From this data I need to copy only that entire column in which the word "ANDE" is found and paste the entire row as below in another sheet:-

1612808125545.png


It it fixed that the word which I have to search will be unique, but it is not fixed that the word which I will search will be in same column, every time it will be changing the position from cell to cell and column to column.
But the given range of data will be fixed.

Many many thanks in advance. if any one can help on this.
 
In your profile you have selected virtually every version of xl
1612821827761.png

You need to go into Account details & unselect all versions of Excel other than 2010.
That way members here will know which version of Excel you are using.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Joe, similarly how can I do for Max and Mark in sheet 3 and 4?

As long as all three values exist, this should work:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim myText() As Variant
    Dim c As Long
    Dim i As Long

'   Enter values to look up in array
    myText = Array("Ande", "Max", "Mark")
   
'   Loop through array
    For i = LBound(myText) To UBound(myText)
       
'       Locate value on sheet 1
        On Error GoTo err_chk
        c = Cells.Find(What:=myText(i), After:=Range("A1"), LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Column
        On Error GoTo 0
       
'       Copy and paste to other sheets
        Columns(c).Copy Sheets(i + 2).Range("A1")
       
    Next i

    Exit Sub
   
err_chk:
'   error handling if cannot find value
    If Err.Number = 91 Then
        MsgBox "Cannot find " & myText(i) & " on Sheet1", vbOKOnly, "ERROR!"
    Else
        MsgBox Err.Number & ": " & Err.Description
    End If
       
End Sub
 
Upvote 0
And thank you for updating your details. :)
Many many Thanks from my bottom of my heart, Joe and Fluff for helping and assisting me. Lots of thanks and Uncountable blessings from my heart to you all.
 
Upvote 0
VBA Code:
Public Sub copyColumn()
    
    Dim Rng As Range: Set Rng = Sheet1.Range("A1").CurrentRegion
    Dim Cl As Long, LstRw As Long
    
        Cl = Sheet1.Cells.Find(What:="Ande", After:=Rng.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, _
        SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Column
        
        LstRw = Cells(Rows.Count, Cl).End(xlUp).Row
        
        Rng.Columns(Cl).Cells(1, 1).Resize(LstRw, 1).Copy Destination:=Sheet2.Range("A1")
End Sub
 
Upvote 0
Did my last code work for you, with your 3 values?
 
Upvote 0
Joe, now I am in trouble that the code which you have provided is working very much fine in system, but what if I will upload that file in the google sheet. Yes, I have tried that also, but it won't work. So, I am Keeping coded file in my system through system sharing and one file which is based on formula is kept in google sheet for remote users where I have used the below formula which is quite working but not what I desired as.

and the formula is =INDEX($A$1:$G$11,ROW($ZZ1),MATCH(1,TRANSPOSE(MMULT(--(TRANSPOSE(ISNUMBER(SEARCH("Ande",$A$1:$G$11)))),ROW($A$1:$G$11)^0)),0))&"".

and the requirement changed as per the use as like this below:-

Driversdriver 1driver 2driver 3driver 4driver 5driver 6
ph noPH1PH2PH3PH4PH5PH6
pickup area91118116111355822542255
08:30 Ande
pickup time08:30 Max09:10 Mark
DropAndeMaxMark

and the data should be pasted as in Sheet1 like below:
driver 1
PH1
9111
08:30 Ande
Ande
and so on similarly in sheet 2 for max and sheet 3 for mark.

If possible kindly please help me on this. The error what I am getting is that if the Ande is written with time and without time in the same column then it is showing #N/A and when if i will remove any of one values from the entire column then it is working . Please have a look on this.
 
Upvote 0

Forum statistics

Threads
1,223,986
Messages
6,175,789
Members
452,670
Latest member
nogarth

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