Excel VBA Class Module

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I am new in learning about class module in Excel VBA, I somewhere read that manipulating data in memory is much faster that manipulating data in excel, I have huge data, and below are the samples, now my question is how can I store all the rows data in the class module related to unique project, like Project 1 is the key for all the rows related to that project and like wise for all project, Project 2 and Project 3 also, after all the data in the memory, when I want to fetch all the records related to particular project just give the project name can fetch all the records related to that project, like after all the data when I give Project 1, I want to fetch all records of Project 1, and can do some manipulation.

Can this is possible, and if yes, how can we do that, please teach me, I want to learn this type of methods in VBA.



Excel Workbook
ABCDE
1ProjectsNameDateAreaEfficiency Status
2Project 1A9/19/2017NPOYes
3Project 1B9/24/2017ZamibiaYes
4Project 2C9/29/2017NPO 2Yes
5Project 3A10/4/2017NPOYes
6Project 1B10/9/2017Season 2No
7Project 2C10/14/2017Season 2No
8Project 3D10/19/2017WCELNo
9Project 2E10/24/2017NPONo
10Project3A10/29/2017ZamibiaYes
Sheet1


Thanks in advance

Thanks
Kashif
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Your class module code would be similar to below. You will need to create instances of the class from your code and populate them from the rows in your worksheet. You will also need to implement an additional method in the class to return records in the format you require, for example, to return an array if that's what you want.

Code:
Private m_intProjectNumber As Integer
Private m_strProjectName As String
Private m_dtmProjectDate As ProjectAreaType
Private m_udtProjectArea As String
Private m_udtProjectEfficiencyStatus As ProjectEfficiencyStatusType

Public Enum ProjectAreaType
  ProjectAreaUSA
  ProjectAreaGermany
  ProjectAreaJapan
  ProjectAreaFrance
  ProjectAreaUnitedKingdom
' Add/Amend areas as needed
End Enum

Public Enum ProjectEfficiencyStatusType
  ProjectEfficiencyStatusYes
  ProjectEfficiencyStatusNo
End Enum

Public Property Let ProjectNumber(ByVal Value As Integer)
  m_intProjectNumber = Value
End Property

Public Property Get ProjectNumber() As Integer
  ProjectNumber = m_intProjectNumber
End Property

Public Property Let ProjectName(ByVal Value As String)
  Value = UCase(Value)
  If Len(Value) = 1 And Asc(Value) >= Asc("A") And Asc(Value) <= Asc("Z") Then
    m_strProjectName = Value
  Else
    Err.Raise vbObjectError + 513, "Project.ProjectName", "Must be single a character between A and Z."
  End If
End Property

Public Property Get ProjectName() As String
  ProjectName = m_strProjectName
End Property

Public Property Let ProjectDate(ByVal Value As Date)
  m_dtmProjectDate = Value
End Property

Public Property Get ProjectDate() As Date
  ProjectDate = m_dtmProjectDate
End Property

Public Property Let ProjectArea(ByVal Value As ProjectAreaType)
  m_udtProjectArea = Value
End Property

Public Property Get ProjectArea() As ProjectAreaType
  ProjectArea = m_udtProjectArea
End Property

Public Property Let ProjectEfficiencyStatus(ByVal Value As ProjectEfficiencyStatusType)
  m_udtProjectEfficiencyStatus = Value
End Property

Public Property Get ProjectEfficiencyStatus() As ProjectEfficiencyStatusType
  ProjectEfficiencyStatus = m_udtProjectEfficiencyStatus
End Property

Furthermore, a class might not be the best way to do this with regards to efficiency. You could simply populate an array of variant type from your worksheet and return a subset of it from a user-defined function. It is up to you.
 
Upvote 0
Hi ParamRay,

Thanks for your precious time for this code, however as I said I am new in class module, I know how to use it, means how to fill the data in class module and how can I retrieve rows for specific projects.

It would be great help, if you please post complete code for the same.

Thanks again for your help.

Thanks
Kashif
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top