Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: VisualBasic  |  size: 1.93 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Function ReadFileFromPath(ByVal FullPath As String, ByRef DateStr As String, ByRef DollarStr As String) As String()
  2.        
  3.     'MsgBox FullPath
  4.    
  5.     Dim Book As Workbook
  6.     Set Book = Workbooks.Open(FullPath, , True)
  7.    
  8.     Dim Sheet As Excel.Worksheet
  9.        
  10.     Set Sheet = Book.ActiveSheet
  11.        
  12.     'Take date
  13.    'Dim DateStr As String
  14.    'Take Dollar
  15.    'Dim DollarStr As String
  16.    'fake param
  17.    Dim OD As Integer
  18.     OD = 1
  19.     Do While Not (Sheet.Cells(OD, 1) Like "Week*")
  20.         OD = OD + 1
  21.     Loop
  22.     DateStr = GlueDollarAndDate(Sheet.Cells(OD, 1))
  23.     DollarStr = TakeDollarWithParams(GlueDollarAndDate(Sheet.Cells(OD, 1)))
  24.     'MsgBox DateStr
  25.    'MsgBox DollarStr
  26.    
  27.    
  28.    
  29.    
  30.    
  31.    
  32.    
  33.     'offset by I - raw and J - column
  34.    Dim i As Integer
  35.     i = 1
  36.     Dim J As Integer
  37.     J = 1
  38.        
  39.     Do While Sheet.Cells(i, 1) <> "Reference Entity"
  40.         i = i + 1
  41.     Loop
  42.    
  43.  
  44. // ------PROBLEM----------//
  45.     Do While Sheet.Cells(i, J) <> "Contracts"  // <<------------- HERE---------<<<
  46.         J = J + 1
  47.     Loop
  48.  
  49.  
  50. // ------PROBLEM---------//
  51.     'max raw
  52.    
  53.     Dim LI As Integer
  54.     LI = i
  55.    
  56.     Do While (Sheet.Cells(LI, 1) <> "")
  57.         LI = LI + 1
  58.     Loop
  59.     LI = LI - 1
  60.    
  61.     'MsgBox LI
  62.    
  63.     Dim ListOfNames() As String
  64.     ReDim ListOfNames(1 To J)
  65.    
  66.     Dim II As Integer
  67.     Dim JJ As Integer
  68.    
  69.     For II = 1 To J
  70.         ListOfNames(II) = Sheet.Cells(II, J)
  71.     Next II
  72.    
  73.    
  74.     'Matrix of Data, will have a dim as ()
  75.    Dim DataMatrix() As String
  76.     ReDim DataMatrix(1 To LI - i, 1 To J)
  77.    
  78.    
  79.     For II = i + 1 To LI
  80.         For JJ = 1 To J
  81.                 DataMatrix(II - i, JJ) = Sheet.Cells(II, JJ)
  82.             Next JJ
  83.     Next II
  84.     'MsgBox DataMatrix(LI - i, J)
  85.    Book.Close
  86.     Set Book = Nothing
  87.     Set Sheet = Nothing
  88.    
  89.     ReadFileFromPath = DataMatrix
  90.    
  91. End Function