Guest User

Untitled

a guest
Aug 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. Private pHeaderNames As Object
  2. Private pHeaderRow As Long
  3.  
  4. Private pSubHeaderNames As Object
  5. Private pSubHeaderRow As Long
  6.  
  7. Private pDataRowStart As Long
  8. Private pInputColStart As Long
  9. Private pTableColStart As Long
  10. Private pHeaderLastCol As Long
  11.  
  12. Private pTblWorksheet As Worksheet
  13. Private pFileURL As String
  14. Private pFileName As String
  15.  
  16.  
  17.  
  18. '---------------------------------------------- Initialization'
  19. Private Sub Class_Initialize()
  20. pHeaderRow = 1
  21. pDataRowStart = 2
  22. pTableColStart = 1
  23. pInputColStart = pTableColStart
  24. pSubHeaderRow = pHeaderRow
  25. pHeaderLastCol = Cells(pHeaderRow, Columns.Count).End(xlToLeft).Column
  26. Set pHeaderNames = CreateObject("Scripting.Dictionary")
  27. Set pSubHeaderNames = CreateObject("Scripting.Dictionary")
  28. End Sub
  29.  
  30.  
  31. Public Property Get FileURL() As String
  32. FileURL = pFileURL
  33. End Property
  34.  
  35. Public Property Let FileURL(Value As String)
  36. pFileURL = Value
  37. End Property
  38.  
  39. Public Property Get FileName() As String
  40. FileName = pFileName
  41. End Property
  42.  
  43. Public Property Let FileName(Value As String)
  44. pFileName = Value
  45. End Property
  46.  
  47.  
  48. Function OpenWorkbook(URL As String, Name As String)
  49. pFileURL = URL
  50. pFileName = Name
  51. Call Workbook_open(pFileURL, pFileName)
  52. End Function
  53.  
  54.  
  55. Public Property Let SetSheet(Value As String)
  56. If pFileName - "" Then
  57. Set pTblWorksheet = ActiveWorkbook.Worksheets(Value)
  58. Else
  59. Set pTblWorksheet = Workbook(pFileName).Worksheets(Value)
  60. End If
  61. End Property
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. Public Property Get TblWorksheet() As Worksheet
  72. TblWorksheet = pTblWorksheet
  73. End Property
  74.  
  75. Public Property Let TblWorksheet(Sheet As Worksheet)
  76. pTblWorksheet = Sheet
  77. End Property
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. '---------------------------------------------- HeaderLastCol'
  91. Public Property Get HeaderLastCol() As Long
  92. HeaderLastCol = pHeaderLastCol
  93. End Property
  94.  
  95. Public Property Let HeaderLastCol(Value As Long)
  96. pHeaderLastCol = Value
  97. End Property
  98.  
  99.  
  100. '---------------------------------------------- HeaderRow'
  101. Public Property Let HeaderRow(Value As Long)
  102. pHeaderLastCol = Cells(pHeaderRow, Columns.Count).End(xlToLeft).Column
  103. pHeaderRow = Value
  104. End Property
  105.  
  106. Public Property Get HeaderRow() As Long
  107. HeaderRow = pHeaderRow
  108. End Property
  109.  
  110.  
  111. '---------------------------------------------- SubHeaderRow'
  112. Public Property Let SubHeaderRow(Value As Long)
  113. pSubHeaderRow = Value
  114. End Property
  115.  
  116. Public Property Get SubHeaderRow() As Long
  117. SubHeaderRow = pSubHeaderRow
  118. End Property
  119.  
  120.  
  121. '---------------------------------------------- InputColStart'
  122. Sub SetInputColStart(KEY As Variant)
  123. pInputColStart = pHeaderNames(KEY)
  124. End Sub
  125.  
  126. Public Property Get InputColStart() As Long
  127. InputColStart = pInputColStart
  128. End Property
  129.  
  130. Public Property Let InputColStart(Value As Long)
  131. pInputColStart = Value
  132. End Property
  133.  
  134.  
  135. '---------------------------------------------- DataRowStart'
  136. Public Property Get DataRowStart() As Long
  137. DataRowStart = pDataRowStart
  138. End Property
  139.  
  140. Public Property Let DataRowStart(Value As Long)
  141. pDataRowStart = Value
  142. End Property
  143.  
  144.  
  145.  
  146. '---------------------------------------------- TableColStart'
  147. Public Property Get TableColStart() As Long
  148. TableColStart = pTableColStart
  149. End Property
  150.  
  151.  
  152. Public Property Let TableColStart(Value As Long)
  153. pTableColStart = Value
  154. End Property
  155.  
  156.  
  157. '---------------------------------------------- HeaderName'
  158. Sub GetHeaderNames()
  159. With pHeaderNames
  160. For i = pTableColStart To pHeaderLastCol
  161. If Not .Exists(UCase(Cells(pHeaderRow, i).Value)) Then
  162. .Add UCase(Cells(pHeaderRow, i).Value), i
  163. End If
  164. Next i
  165. End With
  166. End Sub
  167.  
  168. Function HeaderName(KEY As String)
  169. If pHeaderNames.Exists(KEY) Then
  170. HeaderName = pHeaderNames(KEY)
  171. Else
  172. HeaderName = ""
  173. End If
  174. End Function
  175.  
  176. Function CountHeaderNames()
  177. CountHeaderNames = pHeaderNames.Count
  178. End Function
  179.  
  180. Function PrintHeaderObject()
  181. For Each KEY In pHeaderNames.keys
  182. Debug.Print KEY, pHeaderNames(KEY)
  183. Next
  184. End Function
  185.  
  186.  
  187. '---------------------------------------------- SubHeaderName'
  188. Sub GetSubHeaderNames()
  189. With pSubHeaderNames
  190. For i = pTableColStart To pHeaderLastCol
  191. If Not .Exists(UCase(Cells(pSubHeaderRow, i).Value)) Then
  192. .Add UCase(Cells(pSubHeaderRow, i).Value), i
  193. End If
  194. Next i
  195. End With
  196. End Sub
  197.  
  198. Function SubHeaderName(KEY As String)
  199. If pSubHeaderNames.Exists(KEY) Then
  200. SubHeaderName = pSubHeaderNames(KEY)
  201. Else
  202. SubHeaderName = "" 'or raise an error...
  203. End If
  204. End Function
  205.  
  206. Function CountSubHeaderNames()
  207. CountSubHeaderNames = pSubHeaderNames.Count
  208. End Function
  209.  
  210. Function PrintSubHeaderObject()
  211. For Each KEY In pSubHeaderNames.keys
  212. Debug.Print KEY, pSubHeaderNames(KEY)
  213. Next
  214. End Function
  215.  
  216.  
  217.  
  218. Function RetrieveData(FromSht As Worksheet, ByVal FromTable As cTable)
  219.  
  220. Dim KEY As String
  221.  
  222.  
  223. 'CurrentSht = ActiveSheet
  224. For i = pTableColStart To pHeaderLastCol
  225. KEY = Cells(pHeaderRow, i).Value
  226. If FromTable.HeaderName(KEY) = "" Then
  227. GoTo Nexti
  228. Else
  229. With FromSht
  230. .Activate
  231. rD_LastRow = 10
  232. Set Source = .Range(.Cells(FromTable.DataRowStart, FromTable.HeaderName(KEY)), _
  233. .Cells(rD_LastRow, FromTable.HeaderName(KEY)))
  234. End With
  235.  
  236. With CurrentSht
  237. .Activate
  238. .Range(.Cells(DataRowStart, i), _
  239. .Cells(DataRowStart, i)) _
  240. .Resize(Source.Rows.Count, Source.Columns.Count).Cells.Value = Source.Cells.Value
  241. End With
  242. End If
  243.  
  244.  
  245.  
  246. Nexti:
  247. Next i
  248.  
  249.  
  250. End Function
  251.  
  252. Sub test()
  253.  
  254. Dim sht As Worksheet
  255.  
  256. Set wb = ActiveWorkbook
  257. Set sht = wb.Sheets("Skin(Units)")
  258.  
  259.  
  260. With Worksheets("Skin(Units)")
  261. .Activate
  262. Set SkinUnits = New cTable
  263.  
  264. Debug.Print TypeName(SkinUnits)
  265. SkinUnits.HeaderRow = 1
  266. SkinUnits.SubHeaderRow = 3
  267. SkinUnits.DataRowStart = 4
  268. SkinUnits.GetHeaderNames
  269. SkinUnits.GetSubHeaderNames
  270.  
  271. SkinUnits.PrintHeaderObject
  272. SkinUnits.PrintSubHeaderObject
  273. SkinUnits.SetInputColStart ("Start")
  274. End With
  275.  
  276.  
  277. With Worksheets("Pain(Units)")
  278. .Activate
  279. Set PainUnits = New cTable
  280.  
  281. PainUnits.HeaderRow = 1
  282. PainUnits.SubHeaderRow = 3
  283. PainUnits.DataRowStart = 4
  284. PainUnits.GetHeaderNames
  285. PainUnits.GetSubHeaderNames
  286.  
  287. PainUnits.PrintHeaderObject
  288. PainUnits.PrintSubHeaderObject
  289. PainUnits.SetInputColStart ("Start")
  290. Debug.Print PainUnits.HeaderName("SKU")
  291. Debug.Print TypeName(sht), TypeName(SkinUnits)
  292. Call test22222(SkinUnits)
  293. Call PainUnits.RetrieveData(sht, SkinUnits)
  294.  
  295. End With
  296.  
  297.  
  298.  
  299. End Sub
  300.  
  301.  
  302. Function test22222(ByVal X As cTable)
  303.  
  304.  
  305. Debug.Print X.HeaderRow
  306.  
  307.  
  308. End Function
Add Comment
Please, Sign In to add comment