เรียน อาจารย์
1. ต้องการค้นหาข้อมูลจากอีก Sheet แล้วมาแสดง
ถ้าอยากให้ค้นหาโดยที่ไม่ต้องเปิดไฟล์ที่ต้องการค้นหา จะต้องปรับ Code อย่างไรครับ หรืออาจารย์พอมีวิธีอื่นหรือไม่ครับ
(Data ประมาณ 20กว่า M ครับ)
ไฟล์ : Pre-Arrangement1 - Copy อยู่ในเครื่อง
ไฟล์ : All Data Estimated อยู่ที่ Server ครับ
Code: Select all
Private Sub CommandButton2_Click()
Dim sb As Workbook
Dim sh As Worksheet
Dim rngA As Range
Dim r As Range
Dim strSb As String
Dim Ref As String
Dim f As Boolean
strSb = "\\10.21.4.97\File Sharing2\DataPricing\All Data Estimated.xlsx"
Set sb = Workbooks.Open(Filename:=strSb, UpdateLinks:=False, ReadOnly:=True)
f = False
With ThisWorkbook.Worksheets("Input")
Ref = .Range("F6").Value
For Each sh In sb.Worksheets
Set rngA = sh.Range("a2", sh.Range("a" & sh.Rows.Count).End(xlUp))
For Each r In rngA
If r.Value = Ref Then
.Range("C10").Value = r.Offset(0, 6).Value
.Range("F10").Value = r.Offset(0, 5).Value
.Range("C12").Value = r.Offset(0, 7).Value
.Range("C14").Value = r.Offset(0, 12).Value
.Range("C16").Value = r.Offset(0, 11).Value
.Range("C18").Value = r.Offset(0, 16).Value
.Range("C20").Value = r.Offset(0, 20).Value
.Range("C22").Value = r.Offset(0, 22).Value
.Range("E22").Value = r.Offset(0, 23).Value
f = True
Exit For
End If
Next r
If f Then Exit For
Next sh
End With
sb.Close False
End Sub
2.ต้องการ Search HN โดยค้นหาที่เดียวกันกับข้อ 1 ให้มาแสดงใน ListBox ยัง error อยู่
จะต้องปรับ Code อย่างไรครับ
Code: Select all
Private Sub CommandButton1_Click()
Dim sb As Workbook
Dim sh As Worksheet
Dim rngA As Range
Dim r As Range
Dim strSb As String
Dim Ref As String
Dim f As Boolean
strSb = "\\10.21.4.97\File Sharing2\DataPricing\All Data Estimated.xlsx"
Set sb = Workbooks.Open(Filename:=strSb, UpdateLinks:=False, ReadOnly:=False)
f = False
'Other code
Dim i As Long, j As Long
Dim arr(0, 26) As Variant
Me.ListBox1.Clear
Me.ListBox1.AddItem
For a = 0 To 26
arr(0, a) = sh.Cells(1, a + 1).Value
' Me.ListBox1.List(0, a - 1) = Sheet1.Cells(1, a)
Next a
Me.ListBox1.ColumnCount = 26
Me.ListBox1.List = arr
'Me.ListBox1.Locked = True
ListBox1.ColumnWidths = "25 ,0 ,0 ,0,0 ,64 ,0 ,68 ,60,25, 25,70 ,70 ,0 ,0 ,0 ,0,80,0 ,0 ,0 ,0 ,0 ,0 ,0, 50"
ListBox1.Height = 170
ListBox1.Width = 550
ListBox1.Left = 764
ListBox1.Top = 282
'Other code
'For List Box fill
'For i = 2 To Sheet4.Range("A1000000").End(xlUp).Row
For i = sh.Range("A1000000").End(xlUp).Row To 2 Step -1
If sb.Cells(i, 7).Value = TextBox1.Value Then
Me.ListBox1.AddItem
For x = 1 To 26
Me.ListBox1.List(ListBox1.ListCount - 1, x - 1) = sh.Cells(i, x)
Next x
End If
Next i
ขอบคุณครับ
You do not have the required permissions to view the files attached to this post.