Select Cells and Copy Paste Selected Data

fari1

Active Member
Joined
May 29, 2011
Messages
362
I want to have a code, that gives the output of just selected data. The example is below:

ColumnA
Row
1
2 Alpha
3
4 Beta
5
6 Gamma
7
8 Alpha
9
10 Beta
11
12 Alpha
13
14 Alpha
15
16 Gamma
17
18 Alpha
19
20 Beta


in the above example, in Column A there are multiple cells which contain some text and blank cells, i want the code to select, just those cells which contain Alpha and Beta and paste them in sheet2, as this is the dynamic range, there can be even no data, or row that contain just one cell of data or can be beyond 100 cells of data. any help over it would be greatly appreciated. Also i want the code to just select,copy and paste and not the delete empty or unwanted cells, as the other columns contain some valuable data in the sheet.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Soemthing like this...
Code:
Sub selecttext()
lRow = Sheet2.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    If Range("A" & i) = "Alpha" Or Range("A" & i) = "Beta" Then
        Sheet2.Range("A" & lRow + 1).Value = Sheet1.Range("A" & i)
        lRow = lRow + 1
    End If
Next
End Sub
 
Upvote 0
try this too
Code:
Sub CopyAndPaste()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1:A" & LR)
    .AutoFilter 1, "Alpha", xlOr, "Beta"
    .Copy Sheets("sheet2").Range("a1")
End With

End Sub
 
Upvote 0
Fari
both codes work on this data
Excel Workbook
A
1Data
2Alpha
3Beta
4
5Alpha
6Beta
7Beta
8Alpha
9
10Gamma
11
12Gamma
13Alpha
Sheet1
Excel 2007

HTH
 
Upvote 0
Code:
Sub CopyAndPaste()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Sheets("info").Range("A1:A" & LR)
    .AutoFilter 1, "10-K", xlOr, "10-Q", xlOr, "10-Q/A", xlOr, "10-K/A"
    .copy Sheets("data").Range("a1")
End With
End Sub

this code is giving error on this line

Code:
.AutoFilter 1, "10-K", xlOr, "10-Q", xlOr, "10-Q/A", xlOr, "10-K/A"

wrong no.of arguments,or invalid use of property
 
Upvote 0
pl let me know just one thing, can i add more than two criterias, to find apart from alpha beta and gamma as well, will that be the same code, as i posted
 
Upvote 0
try this one
Code:
Sub CopyAndPaste()
Dim LR As Long
LR = Sheets("info").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("info").Range("A1:A" & LR)
    .AutoFilter 1, Criteria1:=Array("10-K", "10-K/A", "10-Q", "10-Q/A"), Operator:=xlFilterValues
    .Copy Sheets("data").Range("a1")
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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