M
Monomeeth
Hello
I am working on a macro to compare two worksheets to identify matching data.
I have got this to work nicely, but am now trying to make it as user-friendly
as possible so that others can use it without modifying the code. So far I
have got the macro to present the user with three input boxes:
---The 1st asks the user to specify what text the macro will place in a
field to indicate that the record was found.
---The 2nd asks the user to select the range of cells containing the data
they are trying to match.
---The 3rd asks the user to indicate which worksheet the macro has to look
at to find any matching data.
What I am having trouble with is: (1) how to get the user to also specify
the range of cells the macro has to look at to find the data, and (2) how to
get the user to specify the column in which to place the text specified in
the 1st input box.
The code I have so far is below:
Sub FindData()
Dim c As Range
Dim findC As Variant
Response = InputBox(Prompt:="Enter message to place in Cells")
Set MyRange = Application.InputBox( _
Prompt:="Select the range of cells containing the data you are looking
for:", Type:=8)
ComparisonSheet = InputBox( _
Prompt:="Enter the name of the worksheet you wish to investigate?")
Set Sht = MyRange.Parent
For Each c In MyRange
If Not c Is Nothing Then
Set findC = ActiveWorkbook.Sheets(ComparisonSheet).Cells _
.Find(c.Value, LookIn:=xlValues)
If Not findC Is Nothing Then
' Within the quotation marks below enter the Column you want the comments to
appear in
Sht.Range("G" & c.Row).Cells.Value = Response
End If
End If
Next
Excel.Application.SendKeys Keys:="^{HOME}", Wait:=True
DoEvents
MsgBox "Investigation completed."
End Sub
As you can see, the macro looks at the entire worksheet (as specified by the
user in the 3rd input box) to find the matching data. But my preference would
be that the user can also specify the range in that worksheet. This way they
can select the entire worksheet or just a column within the worksheet.
Also, as you can tell from the above code, the macro will place the text (or
response) in the corresponding row in column G of the active worksheet. I
would like the user to be able to either specify the column in which the text
is to be placed, or to have the macro automatically place the text in the
first column after the range of data.
I hope this all makes sense.
Any help would be most appreciated as I'm at a loss.
Joe.
I am working on a macro to compare two worksheets to identify matching data.
I have got this to work nicely, but am now trying to make it as user-friendly
as possible so that others can use it without modifying the code. So far I
have got the macro to present the user with three input boxes:
---The 1st asks the user to specify what text the macro will place in a
field to indicate that the record was found.
---The 2nd asks the user to select the range of cells containing the data
they are trying to match.
---The 3rd asks the user to indicate which worksheet the macro has to look
at to find any matching data.
What I am having trouble with is: (1) how to get the user to also specify
the range of cells the macro has to look at to find the data, and (2) how to
get the user to specify the column in which to place the text specified in
the 1st input box.
The code I have so far is below:
Sub FindData()
Dim c As Range
Dim findC As Variant
Response = InputBox(Prompt:="Enter message to place in Cells")
Set MyRange = Application.InputBox( _
Prompt:="Select the range of cells containing the data you are looking
for:", Type:=8)
ComparisonSheet = InputBox( _
Prompt:="Enter the name of the worksheet you wish to investigate?")
Set Sht = MyRange.Parent
For Each c In MyRange
If Not c Is Nothing Then
Set findC = ActiveWorkbook.Sheets(ComparisonSheet).Cells _
.Find(c.Value, LookIn:=xlValues)
If Not findC Is Nothing Then
' Within the quotation marks below enter the Column you want the comments to
appear in
Sht.Range("G" & c.Row).Cells.Value = Response
End If
End If
Next
Excel.Application.SendKeys Keys:="^{HOME}", Wait:=True
DoEvents
MsgBox "Investigation completed."
End Sub
As you can see, the macro looks at the entire worksheet (as specified by the
user in the 3rd input box) to find the matching data. But my preference would
be that the user can also specify the range in that worksheet. This way they
can select the entire worksheet or just a column within the worksheet.
Also, as you can tell from the above code, the macro will place the text (or
response) in the corresponding row in column G of the active worksheet. I
would like the user to be able to either specify the column in which the text
is to be placed, or to have the macro automatically place the text in the
first column after the range of data.
I hope this all makes sense.
Any help would be most appreciated as I'm at a loss.
Joe.