PDA

View Full Version : [SOLVED:] Copy multiple cells on the same worksheet after a search



simora
09-30-2014, 02:25 AM
I am doing a search and I get the result like this.



With col.Find(ComboBox1, LookAt:=xlWhole)
rsCol = .Column


The search range is restricted to Column Headings.
Now I want to go down that column where my value was found and find every value >0 in that column and copy that and the corresponding value from the same row in Column A to columns CA & CB on the same page.
The Column A values go in Column CA, & the >0 value goes into Col CB

I'm stuck. Can't seem to organise my thoughts on this.
HELP.

simora
10-04-2014, 01:05 AM
Just in case anyone else wanted to see the solution:



Private Sub CommandButton1_Click()

Dim i As Range
Dim r
Dim c
Dim num As Integer
Dim col As Range
Dim rsCol As Long
Dim rng As Range
Dim LastRow

Application.ScreenUpdating = False


LastRow = ActiveSheet.Range("A65536").End(xlUp).Row
With Sheets("Sheet1")
Set col = Range("E1:G1")
End With

With col.Find(ComboBox1, LookAt:=xlWhole)
rsCol = .Column
End With

num = 1
Range(Cells(2, rsCol), Cells(LastRow, rsCol)).Select ' From Row 2 to LastRow


For Each i In Selection

If IsNumeric(i.Value) And i.Value > 0 Then
i.Select
r = ActiveCell.Row
c = ActiveCell.Column

Union(Cells(r, "A"), Cells(r, c)).Select ' Get Col A & Current found column

Selection.Copy
With Selection
ActiveSheet.Paste

Destination:=Worksheets("Sheet2").Range("A65356").End(xlUp).Offset(1, 0)

' Change to to columns CA as per original question

End With

num = num + 1

End If

Next i

amt = num - 1
Application.ScreenUpdating = True

MsgBox "Total Values Copied is : " & amt
Unload Me
Range("A1").Select

End Sub