Confusing Macro and references....

W

ween_boy

I WAS TRYING TO CREATE THIS EFFECT: ENTER A VALUE (IN THIS EXAMPLE I
WAS \"OKCGALTA\") AND CLICK A BUTTON TO RUN A MACRO TO SEARCH A EXCE
SHEET ON A NETWORK DRIVE (P:XXX\ABC.XLS) FOR ALL OF THE VALUES, PAST
ONLY THE ROWS IN WHICH THE VALUE IS.

CURRENTLY, IT ONLY REFERENCES THE CURRENT SHEET (NOT AN EXTERNAL SHEET
AND I HAVE TO GO INTO THE MACRO TO ENTER THE VALUE FOR IT TO LOOK FO
(NOT BEING ABLE TO TYPE \"OKCGALTA\" IN CELL A1, FOR EXAMPLE TO MAKE I
USER FRIENDLY)

ANY HELP WOULD BE MUCH APPRECIATED.

Sub SearchForString()

Dim LSearchRow As Integer
Dim LCopyToRow As Integer

On Error GoTo Err_Execute

LSearchRow = 2

LCopyToRow = 2

While Len(Range("A" & CStr(LSearchRow)).Value) > 0

If Range("B" & CStr(LSearchRow)).Value = "OKCGALTA" Then

Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy

Sheets("Sheet2").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste

LCopyToRow = LCopyToRow + 1

Sheets("Sheet1").Select

End If

LSearchRow = LSearchRow + 1

Wend

Application.CutCopyMode = False
Range("A3").Select

MsgBox "All matching data has been copied."

Exit Sub

Err_Execute:
MsgBox "An error occurred."

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top