Hi!
I was given a pair of spreadsheets that has some custom VB code applied to the main sheet. Currently, the code allows them to pull up the member name by putting in the pass number. What they need is the member name to pull up the number and place the data in the proper cell. I'm new to VB and have been unable to make it work properly at all. Any help is much appreciated.
The main form looks like this (i've changed the last names as these are citizens of the city i work for):
Court 1
Time Code Card # Name Res NR
8am 7809 Nxxx, Keith
The form it pulls the data from looks like this:
Member
Member Name Pass #
AAAAz, Esteban 9636
AAAAn, Lucienne 8921
ABBBB, Erin 9446
ABDDD, Tina 8032
ABRRRR, Stanley C 8020
Here is the code i was given:
Public Function IsWorkbookOpen( _
ByVal WorkbookName As String _
) As Boolean
Dim Workbook As Workbook
For Each Workbook In Workbooks
If Workbook.Name = WorkbookName Then
IsWorkbookOpen = True
Exit Function
End If
Next Workbook
End Function
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FocusRange As Range
Dim Cell As Range
Dim Row As Long
Dim SourceTable As Range
Set FocusRange = Intersect([c11:c92,i11:i92,o11
92,u11:u92,aa11:aa92,ag11:ag92], Target) ' Change the range on this line to include all cells in which an account number can be entered
If Not FocusRange Is Nothing Then
If Not IsWorkbookOpen("Customers.xls") Then
Application.ScreenUpdating = False
Workbooks.Open ThisWorkbook.Path & "\Customers.xls", 2, True
ThisWorkbook.Activate
Application.ScreenUpdating = True
End If
Set SourceTable = Workbooks("Customers.xls").Sheets(1).[A2:F1500]
For Each Cell In FocusRange
If Len(Cell) > 0 Then
Row = 0
On Error Resume Next
Row = Application.Match(Cell, SourceTable.Columns(6), 0)
On Error GoTo 0
If Row > 0 Then
Cell.Offset(ColumnOffset:=1) = SourceTable.Columns(1).Cells(Row)
Else
Cell.Offset(ColumnOffset:=1) = "Not Found"
End If
End If
Next Cell
End If
End Sub
I was given a pair of spreadsheets that has some custom VB code applied to the main sheet. Currently, the code allows them to pull up the member name by putting in the pass number. What they need is the member name to pull up the number and place the data in the proper cell. I'm new to VB and have been unable to make it work properly at all. Any help is much appreciated.
The main form looks like this (i've changed the last names as these are citizens of the city i work for):
Court 1
Time Code Card # Name Res NR
8am 7809 Nxxx, Keith
The form it pulls the data from looks like this:
Member
Member Name Pass #
AAAAz, Esteban 9636
AAAAn, Lucienne 8921
ABBBB, Erin 9446
ABDDD, Tina 8032
ABRRRR, Stanley C 8020
Here is the code i was given:
Public Function IsWorkbookOpen( _
ByVal WorkbookName As String _
) As Boolean
Dim Workbook As Workbook
For Each Workbook In Workbooks
If Workbook.Name = WorkbookName Then
IsWorkbookOpen = True
Exit Function
End If
Next Workbook
End Function
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FocusRange As Range
Dim Cell As Range
Dim Row As Long
Dim SourceTable As Range
Set FocusRange = Intersect([c11:c92,i11:i92,o11
If Not FocusRange Is Nothing Then
If Not IsWorkbookOpen("Customers.xls") Then
Application.ScreenUpdating = False
Workbooks.Open ThisWorkbook.Path & "\Customers.xls", 2, True
ThisWorkbook.Activate
Application.ScreenUpdating = True
End If
Set SourceTable = Workbooks("Customers.xls").Sheets(1).[A2:F1500]
For Each Cell In FocusRange
If Len(Cell) > 0 Then
Row = 0
On Error Resume Next
Row = Application.Match(Cell, SourceTable.Columns(6), 0)
On Error GoTo 0
If Row > 0 Then
Cell.Offset(ColumnOffset:=1) = SourceTable.Columns(1).Cells(Row)
Else
Cell.Offset(ColumnOffset:=1) = "Not Found"
End If
End If
Next Cell
End If
End Sub