Hi,
I Have a piece of code below which loop searches an array for a specific string, once found it selects the cells which contain the text and loops until finished.
What I want to do now is copy the selected cells and paste them to another workbook but I'm having difficulty.
Any help will be appreciated
I Have a piece of code below which loop searches an array for a specific string, once found it selects the cells which contain the text and loops until finished.
What I want to do now is copy the selected cells and paste them to another workbook but I'm having difficulty.
Any help will be appreciated
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]'if the searchreturns a cell[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] If Not c IsNothing Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] 'note theaddress of first cell found[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] firstaddress =c.Address[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Do[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] 'FoundCells is the variable that will refer to all of the[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] 'cellsthat are returned in the search[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] IfFoundCells Is Nothing Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] SetFoundCells = c[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Else[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] SetFoundCells = Union(c, FoundCells)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] 'find thenext instance of "er99"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Set c =.Cells.FindNext(c)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Loop While Notc Is Nothing And firstaddress <> c.Address[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] 'after entiresheet searched, select all found cells[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] FoundCells.Select[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] FoundCells.CopyWorksheets("Sheet2").Range("A1")[/COLOR][/SIZE][/FONT]
Last edited by a moderator: