hariprasadcp
New Member
- Joined
- Dec 27, 2012
- Messages
- 17
Hi,
I am searching for specific text values in another spreadsheet, if it finds I must write in the adjacent column as Available. unfortunately this is not working as expected, What is wrong in the below code? or is there any other code which I could try .
ex:
DC35
DC36
DCU20680
GC070648
Option Explicit
Sub test()
Dim wkbOpen As Workbook
Dim wks As Worksheet
Dim Cell As Range
Dim FoundCell As Range
Dim Wkb As Variant
Set Cell = Application.InputBox( _
Prompt:="Please a cell containing the desired value.", _
Title:="Select a Cell", _
Type:=8)
If Cell Is Nothing Then Exit Sub
Wkb = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", FilterIndex:=1, Title:="Select a Workbook", MultiSelect:=False)
If Wkb = False Then Exit Sub
Application.ScreenUpdating = False
Set wkbOpen = Workbooks.Open(FileName:=Wkb)
With wkbOpen
For Each Cell In UserRange
Set FoundCell = Cells.Find(What:=Cell.Value, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) 'Adjust the parameters, accordingly
If Not FoundCell Is Nothing Then
Cell.Offset(, 1).Value = Available
Exit Sub
End If
Next Cell
End With
Application.ScreenUpdating = True
End Sub
I am searching for specific text values in another spreadsheet, if it finds I must write in the adjacent column as Available. unfortunately this is not working as expected, What is wrong in the below code? or is there any other code which I could try .
ex:
DC35
DC36
DCU20680
GC070648
Option Explicit
Sub test()
Dim wkbOpen As Workbook
Dim wks As Worksheet
Dim Cell As Range
Dim FoundCell As Range
Dim Wkb As Variant
Set Cell = Application.InputBox( _
Prompt:="Please a cell containing the desired value.", _
Title:="Select a Cell", _
Type:=8)
If Cell Is Nothing Then Exit Sub
Wkb = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", FilterIndex:=1, Title:="Select a Workbook", MultiSelect:=False)
If Wkb = False Then Exit Sub
Application.ScreenUpdating = False
Set wkbOpen = Workbooks.Open(FileName:=Wkb)
With wkbOpen
For Each Cell In UserRange
Set FoundCell = Cells.Find(What:=Cell.Value, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) 'Adjust the parameters, accordingly
If Not FoundCell Is Nothing Then
Cell.Offset(, 1).Value = Available
Exit Sub
End If
Next Cell
End With
Application.ScreenUpdating = True
End Sub