Hi,
I have a column (column A) which contains letters and where I want to detect all a and store these into malomrade. When all values in column A are evaluated and for these values which have meet the criteria (to be an "a") and hence are stored in malomrade, these values should be pasted in column A on the next sheet. They should be pasted after each other (thus without any blanks between them. For ex if there are five "a":s stored in malomrade these should be pasted into cell a1 to a5).
Though this won't happen, and I guess it has something to do with the evaluation, ie not only "a":s are stored into malomrade. Also something is probably not properly set up when it comes to specifying the area for pasting. All help or input appreciated.
[VBA] Sub test()
Dim omrade As Range
Dim malomrade As Range
Dim annatomrade As Range
'Dim catcharea As Range
Dim c As Range
Set omrade = Range("A1:A20")
For Each c In omrade
If c = "a" Then _
'If omrade Is Nothing Then Set omrade = c Else
Set malomrade = Application.Union(omrade, c)
End If
Next c
Set annatomrade = Worksheets(2).Cells(malomrade.Rows.Count, malomrade.Columns.Count)
malomrade.Copy Destination:=annatomrade
End Sub[/VBA]
Edited by Aussiebear: Danlu, please use the vba button to enclose the code you post to this forum. This function makes the code so much easier to read.