Hello,
It's me again. I am wondering if you could help me with two more things. I need help in merging two macros (one that opens the folder and lets you pick the file you want) and other is one I recorded on how to sort a data file into excel. I need to be able to pick the file I want to open, but I want the macro to complete the text import wizard task for me.
Here is the codes I've been using for these tasks (I am using "Data" as a filename):
Sub OpenWorkbook()
Application.Dialogs(xlDialogOpen).Show
End Sub
Sub TextImportWizard()
Workbooks.OpenText Filename:= _
"Data"
End Sub
Sub FormatText()
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
Array(0, 1), Array(12, 1), Array(24, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(41 _
, 1), Array(42, 1), Array(47, 1), Array(49, 1), Array(52, 1), Array(53, 1), Array(54, 1), _
Array(55, 1), Array(56, 1), Array(59, 1), Array(61, 1), Array(62, 1), Array(70, 1), Array( _
71, 1), Array(74, 1), Array(75, 1), Array(83, 1), Array(84, 1), Array(96, 1), Array(99, 1), _
Array(107, 1), Array(115, 1), Array(120, 1), Array(123, 1), Array(131, 1), Array(133, 1), _
Array(134, 1), Array(137, 1), Array(145, 1), Array(153, 1), Array(154, 1), Array(155, 1), _
Array(156, 1), Array(157, 1), Array(160, 1), Array(161, 1), Array(162, 1), Array(182, 1), _
Array(197, 1), Array(198, 1), Array(218, 1), Array(233, 1), Array(234, 1), Array(237, 1), _
Array(238, 1), Array(246, 1), Array(254, 1), Array(262, 1), Array(270, 1), Array(278, 1)) _
, TrailingMinusNumbers:=True
End Sub
When I tried to combine the two and run it, I got a "Syntax error" that I don't know how to fix. The combined code looks something like this:
Sub TextImportWizard()
Workbooks.OpenText Filename:= _
"Data"
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
Array(0, 1), Array(12, 1), Array(24, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(41 _
, 1), Array(42, 1), Array(47, 1), Array(49, 1), Array(52, 1), Array(53, 1), Array(54, 1), _
Array(55, 1), Array(56, 1), Array(59, 1), Array(61, 1), Array(62, 1), Array(70, 1), Array( _
71, 1), Array(74, 1), Array(75, 1), Array(83, 1), Array(84, 1), Array(96, 1), Array(99, 1), _
Array(107, 1), Array(115, 1), Array(120, 1), Array(123, 1), Array(131, 1), Array(133, 1), _
Array(134, 1), Array(137, 1), Array(145, 1), Array(153, 1), Array(154, 1), Array(155, 1), _
Array(156, 1), Array(157, 1), Array(160, 1), Array(161, 1), Array(162, 1), Array(182, 1), _
Array(197, 1), Array(198, 1), Array(218, 1), Array(233, 1), Array(234, 1), Array(237, 1), _
Array(238, 1), Array(246, 1), Array(254, 1), Array(262, 1), Array(270, 1), Array(278, 1)) _
, TrailingMinusNumbers:=True
End Sub
In addition to problems with the above, I have problems when I try to sort the date in my spreadsheet using a set column of values (from a separate spreadsheet). I get a debug error whenever I try to run the following code:
Sub Name()
Dim x As Integer
Dim i As Integer
Dim y As Integer
Dim b As Integer
Dim z As String
Worksheets("Sheet 2").Select
Range("a2").Select
x = Range("A2", Range("a2").End(xlDown)).Cells.Count
Dim codes(10)
For i = 1 To x
codes(i) = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
MsgBox codes(i)
Next i
Worksheets("Sheet1").Select
Range("a2").Select
Do Until IsEmpty(ActiveCell)
For b = 1 To x
z = codes(b)
If ActiveCell.Value = codes(b) Then
y = y + 1
End If
Next b
Debug.Print y
If y = 0 Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
y = 0
Loop
End Sub
Thanks,
Svetlana Duray