สอบถามเกี่ยวกับการเชื่อต่อคำสั่ง VB ค่ะ

อยากจะทราบว่า ถ้าเรามีคำสั่งหลายๆคำสั่ง  เช่น

Option Explicit

Public Sub CopyRegis() '¤Ñ´ÅÍ¡àÅ¢·ÐàºÕ¹¨Ò¡ªÕ·3ÁÒÂѧªÕ·1
    Sheets("Sheet3").Select
     Range("a2:a20").Copy
    Sheets("Sheet1").Select
    Range("a2:a20").Select
    ActiveSheet.Paste
End Sub
---------------------------------------------------------------------------------------------------------

Public Sub Class() '¡ÒÃËÒ»ÃÐàÀ·
Dim registration As String 'àÅ¢·ÐàºÕ¹âç§Ò¹
Dim arrayRegis() As String '»ÃÐàÀ·
Dim intLine As Integer

intLine = 2
    While Range("A" & intLine).Value <> ""
        registration = Range("A" & intLine).Value
        
        arrayRegis = Split(registration, "-", -1, 1)
        arrayRegis = Split(arrayRegis(1), "ร้องไห้", -1, 1)

       Worksheets("sheet1").Range("E" & intLine).Value = arrayRegis(0)
       intLine = intLine + 1
    Wend
End Sub

-------------------------------------------------------------------------------------------------------

Public Sub search_coefficient() 'ËÒÊÑÁ»ÃÐÊÔ·¸ÔìºÕâÍ´Õ¹éÓ·Ôé§
Dim search_class() As String ' add array for search 20
Dim search_coefficient() As String ' add array for keep coefficient data 20
Dim i As Integer
Dim j As Integer 'add for keep count search coefficient
Dim c_class() As String 'customer class
Dim c_coefficient() As String 'customer coefficient
Dim no_c As Integer 'Number of customer
Dim no_search As Integer 'Number of search

'*********************************************************************************
i = 2
no_search = 0
'If you need columnE u must enter No.5
Do Until Worksheets("sheet1").Cells(i, 5).Value = ""
    i = i + 1
    no_search = no_search + 1
Loop
no_search = no_search + 1
ReDim search_class(0 To no_search)
ReDim search_coefficient(0 To no_search)
'*********************************************************************************
i = 4
no_c = 0
Do Until Worksheets("sheet2").Cells(i, 1).Value = ""
    i = i + 1
    no_c = no_c + 1
Loop

ReDim c_class(1 To no_c)
ReDim c_coefficient(1 To no_c)

i = 4

For i = 4 To no_c
    c_class(i) = Worksheets("sheet2").Cells(i, 1).Value
    c_coefficient(i) = Worksheets("sheet2").Cells(i, 8).Value
Next i

'search_class = Worksheets("sheet1").Range("e2").Value
'Add all search class to array
For i = 2 To no_search
'If you need columnE u must enter No.5
search_class(i) = Worksheets("sheet1").Cells(i, 5).Value
Next i

i = 4
For i = 4 To no_c
    For j = 2 To no_search
        If c_class(i) = search_class(j) Then
        search_coefficient(j) = c_coefficient(i)
        End If
    Next j
Next i

For i = 2 To no_search
    If search_coefficient(i) = "" Then
    Worksheets("sheet1").Cells(i, 8).Value = "0"
    Else
    Worksheets("sheet1").Cells(i, 8).Value = search_coefficient(i)
    End If
Next i

End Sub

-------------------------------------------------------------------------------------------------------
Public Sub seach_capacity() '¡ÒÃËÒ¡ÓÅѧ¡ÒüÅÔµ
Dim txtText As String
Dim arrayText
Dim i As Integer
Dim intLine As Integer
Dim no_c As Integer
Dim strnum As String


intLine = 2 'àÃÔèÁ¡Ò÷ӧҹµÑé§áµèá¶Ç·ÕèÊͧ

While Range("C" & intLine).Value <> "" 'While loop ¨Ð·Ó§Ò¹¨¹¨º µÑé§áµècolumn C ¨¹¶Ö§ºÃ÷Ѵ·ÕèäÁèÁÕ¢éÍÁÙÅ

   'àÃÔèÁ·Ó§Ò¹µÑé§ààµè C2
    txtText = Range("C" & intLine).Value
    arrayText = Split(txtText, " ", -1, 1)
    no_c = UBound(arrayText) 'UBound ãªéÊÓËÃѺ index ·ÕèÁÒ¡·ÕèÊØ´¢Í§ Array
    
    For i = 0 To no_c
        If IsNumeric(arrayText(i)) Then '¿Ñ§ªÑè¹IsNumeric¹Õé¨Ðãªé·´ÊͺµÑÇÍÑ¡ÉÃàÅ¢(¶éÒãªè it will return TURE)
            strnum = arrayText(i) 'srt ÂèÍÁÒ¨Ò¡ string
               Range("F" & intLine).Value = strnum
        End If
        
    Next i
    
    intLine = intLine + 1 '¡ÒÃà¾ÔèÁ¨Ó¹Ç¹á¶Ç
              
Wend
End Sub
-------------------------------------------------------------------------------------------------------

Public Sub BODLoadingTest()
Dim x As String  '¡ÓÅѧ¡ÒüÅÔµ
Dim y As String   'ÊÑÁ»ÃÐÊÔ·¸Ôì»ÃÔÁÒ³¹éÓ·Ôé§
Dim z As String   'BODLoadong
Dim no_c As Integer
Dim intLine As Integer

intLine = 2

While Range("F" & intLine).Value <> "" And Range("H" & intLine).Value <> ""
    x = Range("F" & intLine).Value
    y = Range("H" & intLine).Value

    z = x * y
    Range("J" & intLine).Value = z

    intLine = intLine + 1

Wend
End Sub





ต่อกันไปเรื่อยๆ โดยคำสั่งเเต่ละคำสั่งเชื่อมกัน  ปรกติถ้าเรียกใช้งานต้องกดใช้งานตามที่เราต้องการ  เเต่ถ้าต้องการให้ทำงานโดยเรียกใช้งานเเค่ครั้งเดียวได้ไหมค่ะ  เเล้วจะต้องทำอย่างไร  ><     (มีพี่คนนึงบอกมาว่า ต้อง เก็บไว้ใน module เดียวกัน)
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่