Option Explicit
Option Compare Text
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
DoFill
End Sub
Private Sub ListBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 13 Then DoFill
End Sub
Private Sub UserForm_Initialize()
TextBox1 = ActiveCell.Value
ListBox1.List() = Range("Ref" & TextBox1).Value
ListBox1.ListIndex = 0
End Sub
Sub DoFill()
Dim MyCell As String
Dim Tmp1 As String, Tmp2 As String, Tmp3 As String, Tmp4 As String
Application.ScreenUpdating = False
MyCell = ActiveCell.Address
Worksheets("sheet" & TextBox1).Select
Tmp1 = Cells(ListBox1.ListIndex + 1, 3).Value
Tmp2 = Cells(ListBox1.ListIndex + 1, 4).Value
Tmp3 = Cells(ListBox1.ListIndex + 1, 5).Value
Tmp4 = Cells(ListBox1.ListIndex + 1, 6).Value
Worksheets("Data").Select
Range(MyCell).Select
ActiveCell.Offset(0, 0).Formula = Tmp1
ActiveCell.Offset(0, 1).Formula = Tmp2
ActiveCell.Offset(0, 2).Formula = Tmp3
ActiveCell.Offset(0, 3).Formula = Tmp4
ActiveCell.Offset(0, 3).Select
Unload UserForm1
Application.ScreenUpdating = True
End Sub
Sub Shows()
On Error Resume Next
UserForm1.Show False
End Sub
Sub DoNames()
Dim Nm, ShName As String, Ref As String
Dim i As Integer
For Each Nm In ActiveWorkbook.Names
If Left(Nm.Name, 3) = "Ref" Then Nm.Delete
Next
For i = 2 To Sheets.Count
Ref = "Ref" & Right(Sheets(i).Name, Len(Sheets(i).Name) - 5)
ShName = "=" & Sheets(i).Name & "!A:C"
ActiveWorkbook.Names.Add Name:=Ref, RefersTo:=ShName
Next
End Sub
Option Explicit
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column() = 6 And Target.Text <> "" Then
DoNames
Target.Select
Shows
End If
End Sub
Private Sub Workbook_Open()
DoNames
End Sub
|