View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bruno Campanini[_3_] Bruno Campanini[_3_] is offline
external usenet poster
 
Posts: 52
Default Transfer selected rows to sheet

"chris100" wrote in
message ...

Bruno,

That 's the problem that i've met now - could you please write down a
simple solution to the situation you mention?


Here is quite a simple code.
Define how many columns involved (n), together with
source and target top left cells (SourceRange, TargetRange).
Let me know if you need any changes, or if you find
any bugs.

==========================================
Sub Button18_Click()
Dim SourceRange As Range, TargetRange As Range
Dim SearchRange As Range, LastWrittenCell As Range
Dim i, n As Integer, ItemToSearchFor
'--------------------------------------
' User definitions
n = 5 ' number of columns to append
Set SourceRange = [AA10]
Set TargetRange = [AG10]
'--------------------------------------
Set SearchRange = Range(SourceRange, SourceRange.End(xlDown))
Set LastWrittenCell = TargetRange.End(xlDown)

ItemToSearchFor = InputBox("Item To Search For:" & vbCrLf & "(case
sensitive)")
If ItemToSearchFor = "" Then
Exit Sub
End If

For Each i In SearchRange
If i.Value = ItemToSearchFor Then
Range(i, i.Offset(0, n - 1)).Copy LastWrittenCell.Offset(1, 0)
End If
Next

End Sub

==============================================

Bruno