Sub HIADataConvert()
DirectoryPath = "C:/XXXX"
Set FSO = CreateObject("Scripting.FilesystemObject")
Set FileList = FSO.GetFolder(DirectoryPath)
Dim Druglist()
Set MasterBook = Worksheets.Add
Range("A1").Resize(1, 7) = Array("Medicine", "Dosage Strength", "Dosage Type", "Type", "Price Type", "Price Value", "Availability")
For Each FileItem In FileList
If InStr(UCase(FileItem.Name), "XLS") Then
Set CloseMe = Workbooks.Open(FileItem.Path, ReadOnly:=True)
CloseMe.Activate
EndRow = Range("A" & Rows.Count).End(xlUp).Row
ReDim Druglist(EndRow * 6, 6)
For i = 1 To EndRow
If Cells(i, 1).Value = "Medicine" Then
StartRow = i
Cells(i, 1).Offset(1, 0).Activate
Exit For
End If
Next
DrugIterator = 0
For i = ActiveCell.Row To EndRow
If Cells(i, 1).Value <> "" Then
Cells(i, 1).Activate
DrugName = Left(Cells(i, 1).Value, InStr(Cells(i, 1).Value, "-") - 2)
DosageType = Right(Cells(i, 1).Value, Len(Cells(i, 1).Value) - InStrRev(Cells(i, 1).Value, " "))
Strength = Mid(Cells(i, 1).Value, Len(DrugName) + 4, Len(Cells(i, 1).Value) - Len(DrugName) - Len(DosageType) - 3)
For k = 0 To 1
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Offset(0, 1).Value <> "" Then
For J = 0 To 2
Druglist(DrugIterator + J, 0) = DrugName
Druglist(DrugIterator + J, 1) = Strength
Druglist(DrugIterator + J, 2) = DosageType
Druglist(DrugIterator + J, 3) = ActiveCell.Offset(0, 1).Value
Druglist(DrugIterator + J, 4) = Cells(StartRow, J + 4).Value
Druglist(DrugIterator + J, 5) = ActiveCell.Offset(0, J + 2).Value
Druglist(DrugIterator + J, 6) = ActiveCell.Offset(0, 5).Value
Next
DrugIterator = DrugIterator + J
End If
Next ' OEM vs Generics
End If
Next 'drug
End If
CloseMe.Close
MasterBook.Activate
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(UBound(Druglist) + 1, UBound(Druglist, 2) + 1) = Druglist
Next 'file
MasterBook.Activate
Columns("A:D").Insert
Range("A1").Resize(1, 4) = Array("Country", "Year", "Month", "Transaction")
Range("A2:F2").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
Selection.Merge True
Range("A2").Select
Sheets("Sheet1").Select
Selection.Copy
Sheets("Sheet2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Columns("A:A").ColumnWidth = 20.67
Range("A3").Select
Application.CutCopyMode = False
Range("A2").Select
Selection.TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=",", FieldInfo:=Array(Array(1, 1), Array(2, 1))
Range("B2").Select
Selection.TextToColumns Destination:=Range("B2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, OtherChar _
:=",", FieldInfo:=Array(Array(1, 9), Array(2, 1), Array(3, 1))
Range("D2").FormulaR1C1 = "=Sheet1!R[2]C[-3]"
Range("A3").FormulaR1C1 = "=R[-1]C"
Range("A3:D3").FillRight
MsgBox "I'm guessing on the column here, search to CHEESE, and put in a usable column"
EndRow = Range("E" & Rows.Count).End(xlUp).Row
Range("A3:D" & EndRow).FillDown
MsgBox "HIA Data was copied in the new format"
End Sub
Bookmarks