Excel VBA - sort and copy to another cell

oceyuboglu

New Member
Joined
May 29, 2019
Messages
5
I have a very long list of data on the "A" column of "Sheet1" and i need to sort the data in the column A by text beginning with "116," and then copy the lines with "116," to another cell in the same worksheet. Then i need to do text to column by delimited with comma.
I have search the forum but couldnt find anything similar.

Can anyone support in this?

Thanks.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi
I would carry out the Text to Columns conversion first.
Then you could use Advanced Filter to extract the rows you need to a separate sheet.
Assuming yoursheet has a row of header in row 1, and column A had a header in A1 of "Code"
Then on sheet2 in Cell A1 enter Code and in A2 enter your 116 That is space followed by 116
Then whilst on sheet 2, highlight cells A1:A2,
Data > Advanced Filter >Criteria =A1:A2
Source =Sheet1! followed by your entire range
Click copy to Another location and for Destination just enter A5
All of the rows beginning " 116" will be copied across to sheet2
 
Upvote 0
Thanks for your answer. Is there anyway to do it by macro?

I tried below code and i gave an error.

Sub sort_click
Dim x as integer
Dim textstring as string
Dim erow as long

x=1
erow=0

Do while Sheet1.Cells(x,1) <>""
If Instr(Sheet1.Cells(x,1)), "116,")>0 Then
textstring=Sheet1.Cells(x,1)
erow=erow+1
Sheet1.Cells(erow,2)=textstring
End if
x=x+1
Loop
End sum
 
Upvote 0
I managed to do this by recording macro. Thanks for your helps.
However, the filtered data i want to copy is about 25 rows however below code is pasting all the rows downwards(it s about 1 million rows) in the file. So after pasting, excel is working so slow and is more than 10mbs.

I wanted to ask how i can only copy the cells with values and exclude blank cells?

Below is the code i used. I tried to copy all the lines and then clear the contents of the cells after 25th row. But didnt work.

VBA Code:
    Workbooks.OpenText Filename:=Application.GetOpenFilename(FileFilter:=Filt, Title:=Title), _
        Origin:=857, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
        , Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
        Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1)), _
        TrailingMinusNumbers:=True
    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$V$999999").AutoFilter Field:=1, Criteria1:="116"
    'Buradan itibaren aşağığısı yeni eklenildi
    Dim LR As Long, LR2 As Long
    LR = Range("B" & Rows.Count).End(xlDown).Row
    Range("B2:D" & LR).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Windows("EPDM Feasibility 1.0b.xlsm").Activate
    Range("D35").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False
    Windows("Worksheet1.xlsm").Activate
    LR2 = Range("D" & Rows.Count).End(xlDown).Row
    Range("D61:F" & LR).SpecialCells(xlCellTypeVisible).Select
    Selection.ClearContents
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,109
Members
448,548
Latest member
harryls

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