Simplify VBA variables with Sub, Function, or Object

First, using input and a “Search” command button, my code declares many viariables that sort data (Zip, Client Name, Last Service Date, etc.) from an excel spreadsheet and place it into a VBA userForm ListBox. Multiple clients will are added line by line. Once in the listbox, a command button “Continue” will use the data to place that data plus a few other pieces of new data(Specific messages, Time Since Service, Phone Number) into a new exel worksheet.

Instead of having similar code with many variables for the “Continue” feature(the second search), I would rather have an object, sub or some other device to hold/create variables and simplify the code.

The following functions are part of the Sub and dynamically retrive the index of cells using listColumn references. The dataColOffset() function is used to find the offset of cells being referenced.

Public Function dataColIndex(colName As String) As Integer

    Dim lo As ListObject
    Set lo = Worksheets("Database").ListObjects("Table3")
    
    dataColIndex = lo.ListColumns(colName).Index
    
    End Function
    
    
    Public Function dataColOffset(changeItem As String, searchItem As String) As Integer
    
    dataColOffset = dataColIndex(changeItem) - dataColIndex(searchItem)

The following Sub has variables that retrieve data from an excel worksheet when a search bigins. This is the first search which will later have code to add names to the listBox. For now, I am stuck on trying to simplify.

Private Sub CommandButton3_Click()
    Dim SearchCol As Range
    SearchBy = ComboBox1.Text
    SearchValue = TextBox1.Text
    Amount = ComboBox2.Text
    Set SearchCol = Worksheets("Database").ListObjects("Table3").ListColumns(SearchBy)

    Dim Name As String
    Dim Zip As Integer
    Dim ContactDate As Date
    Dim ContactAttempt As Date
    Dim ContactMethod As String
    Dim Company As Sring
    Dim LastTuned As Date
    Dim MonthsPerTune As Integer
    Dim City As String
    
    For Each Cell In SearchCol
        'set the columns searched
        Set Name = Cell.Offset(0, dataColOffset("Full Name", SearchBy))
        Set Zip = Cell.Offset(0, dataColOffset("ZipCode", SearchBy))
        Set ContactDate = Cell.Offset(0, dataColOffset("Successful Contact Date", SearchBy))
        Set ContactAttempt = Cell.Offset(0, dataColOffset("Contact Attempt Date", SearchBy))
        Set ContactMethod = Cell.Offset(0, dataColOffset("Contact Method", SearchBy))
        Set Company = Cell.Offset(0, dataColOffset("Company", SearchBy))
        Set LastTuned = Cell.Offset(0, dataColOffset("Last Tuned", SearchBy))
        Set MonthsPerTune = Cell.Offset(0, dataColOffset("Month Per Tune", SearchBy))
        Set City = Cell.Offset(0, dataColOffset("City", SearchBy))
        Next
End Sub

As I stated previosuly, I would rather store these variables in something else such as an object or another sub so that I can place the code in the first and second search Subroutines instead of writing it all over agian. Any ideas to store these variables more easily?

A few options I have thought about are:

Is there some way to use getters and setters to create objects without having to set the member variables manually in each sub?

Is there a way to call a sub to create ClientObject(s) that won’t go out of scope within another sub?

Any other ideas?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật