Find specific item in cell and move entire column

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
173
Could someone help with this one?

I want to search each cell in row 2 for "*.TXT". Once the cell in row 2 is found that contains *.TXT, I want to move (or copy) that ENTIRE column to coulmn A.

Thanks in advance!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
this should be easy just wondering are you looking for exactly *.TXT in a cell or anything that ends with .txt or a specific file?
 
Upvote 0
this just finds *.TXT in row 2 then copys the column to A
Code:
Sub Macro1()
  
For x = 1 To 256
findd = Cells(2, x).Value
If findd = "*.TXT" Then
    Columns(x).Copy
    Columns(1).Select
    ActiveSheet.Paste
Else
End If
Next
End Sub
 
Upvote 0
QuietRiot -

Thank you for your help, but you are right - I want to find ANYTHING that ends in .txt. (I thought that "*.TXT" would do it.

I tried your macro and it didn't initially work for me. I had a cell that contained "43101.TXT". I amended your code to read "43101.TXT" instead of "*.TXT" (just to try the code) and it worked perfectly. HOWEVER,

That was just an example I had. I may have a "68105.TXT" or a "737308.TXT", so I need for the code to look for anything that ends in ".TXT".

Could you help me with that?

Thanks!
 
Upvote 0
yah no problem

real easy fix alls you have to do is put it in a string and then get Right of that string 4 digits.

ill post the code in a second
 
Upvote 0
try this

Code:
Sub Macro1()
  
For x = 1 To 256
findd = Cells(2, x).Value
findd = Right(findd, 4)
findd = UCase(findd)
If findd = ".TXT" Then
    Columns(x).Copy
    Columns(1).Select
    ActiveSheet.Paste
Else
End If
Next
End Sub

the ucase part of it turns it all upper case just in case its .txt instead of .TXT
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

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