Microsoft Excel - VBA code for formatting date file into excel and for sorting by number

Asked By Svetlana Duray
23-Oct-08 05:26 PM

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

 

 

read this link  read this link

24-Oct-08 07:13 AM
http://74.125.45.104/search?q=cache:tLytexTiqfYJ:research.wsulibs.wsu.edu:8080/dspace/bitstream/2376/1109/10/Carroll%2520MERGE%2520MACRO%2520INSTRUCTIONS.doc+merging+two+macros&hl=en&ct=clnk&cd=1&gl=in

http://www.esds.ac.uk/international/elearning/limmd/materials/LIMMD-unit4/page5-4-2.html
Create New Account
help
How can I make my data show as flashing in Excel? Excel Excel Miscellaneous Discussions Microsoft Excel (1) Excel (1) Application.OnTime (1) Worksheet (1) Workbook (1) Macro (1) VBA (1) Font.ColorIndex (1 if you insist, see Chip Pearson's site for VBA code. http: / / www.cpearson.com / excel / BlinkingText.aspx Gord Dibben MS Excel MVP This was great - thank you. My boss loved it. Now I have another question
Printing Excel Worksheets Excel Is there a possible way to print a double sided worksheet from two separate worksheets? Excel Miscellaneous Discussions Microsoft Excel (1) Worksheets (1) Excel (1) I assume you mean double-sided sheet of paper from two worksheets
VBA to compress photos in an excel worksheets Excel I need to write some VBA code, to compress several photos in my excel worksheets. Is there anyone can help me? Thanks! Excel Miscellaneous Discussions VBA (1) Afb1389213c28977 (1) Gsnu200798 (1) Lnk (1) Gst (1) http: / / groups.google com / group / microsoft.public.excel.programming / browse_thread / thread / afb1389213c28977 / 1201ee9ee3bd3c87?lnk = gst&q = compress+pictures#1201ee9ee3bd3c87 - - Gary''s Student - gsnu200798
How to find exact differences between two worksheets Excel Excel Worksheet Discussions Microsoft Excel (1) Uniques (1) AEC04CCD8AD6 (1) Bliengme (1) Caps (1) Duplicates This site is great for finding Uniques / Duplicates: http: / / www.cpearson.com / excel / Duplicates.aspx PLEASE write your message in this white space next time best wishes - - Bernard V Liengme Microsoft Excel MVP http: / / people.stfx.ca / bliengme remove caps from email keywords: How, to, find, , exact
Is there any option to group Worksheets? Excel Please, let me know if there is any option in Microsoft Excel to Group Worksheets. Excel Miscellaneous Discussions Microsoft Excel (1) Worksheets (1) Hiright (1) Ungroup (1) Chick (1) hi right click any sheet tab