+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    72

    Recorded macro doesn't seem to provide expected result

    Hi you all,

    Normally I keep trying until I find what's wrong but this time I could use some help.

    On column A, I simply do an A-Z sort that gives the expected result. So I recorded it as a macro.
    In column G is a code that corresponds with column A. When the marcro is executed Column A is sorted but the corresponding value in G stays where it is.
    Clicking the A-Z button works. But when that action is recorded as a macro I get the above quirck.

    Since VBA is not my beef, I don't really know what wrong...

    cheers,


    edit; Doh, Monday morning; This should go into the excel section.

    [MOD EDIT - moved]

    Jeroen
    Last edited by Jeroen1000; 09-21-2009 at 09:03 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Recorded macro doesn't seem to provide expected result

    Can you post the code that is not working. Don't forget to use code tags.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    72

    Re: Recorded macro doesn't seem to provide expected result

    hi Andy,

    I think I got it. There was a formula on a column that changed my expected result. A bit stupid I didn't notice really.

  4. #4
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Recorded macro doesn't seem to provide expected result

    Recorded macros generally need tidying up, but if you are satisfied with your solution please mar this thread solved.


    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  5. #5
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    72

    Re: Recorded macro doesn't seem to provide expected result

    I usually do my best cleaning them. I am curious how one would grade my code;

    Code:
    
    Sub test()
    
    
        Dim Eurocode As String
        Dim Stickers As String
        Dim Verpakken As String
        Dim Eenheid As Integer
           
       ' Ask for Eurocode
       Eurocode = InputBox("Geef een Eurocode in en klik op OK", "Invoer vereist")
       
       
    annuleer:
       ' Provide the option to cancel
       If StrPtr(Eurocode) = 0 Then
       MsgBox "U heeft de invoer onderbroken. Er zijn geen gegevens toegevoegd", vbExclamation, "Waarschuwing"
       Exit Sub
       End If
       
       ' Keep asking for input if someone clicked OK but didn't fill anything in
       Do While Len(Eurocode) = 0
       Eurocode = InputBox("U heeft niets ingetypt. Typ een Eurocode in of klik op annuleren ", "Invoer vereist")
         ' cancelling still has to be possible
         If StrPtr(Eurocode) = 0 Then GoTo annuleer
       Loop
       
    
       
       ' asking a few questions
       Stickers = MsgBox("Moeten er stickers gemaakt worden?", vbQuestion + vbYesNo, "Keuze vereist")
       If (Stickers = vbNo) Then
       Stickers = "NEE"
       Else
       Stickers = "JA"
       End If
       
       Verpakken = MsgBox("Moet er verpakt worden?", vbQuestion + vbYesNo, "Keuze vereist")
       If (Verpakken = vbNo) Then
       Verpakken = "NEE"
       Else
       Verpakken = "JA"
       End If
    
        ' fetch the last row.
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        
        ' doesn't work yet.
        Cells(1, 1).Value = Jeroen
      
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
       ' sorting thingy
        Columns("A:A").Select
        ActiveWorkbook.Worksheets("Artikelen").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Artikelen").Sort.SortFields.Add Key:=Range("A1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Artikelen").Sort
            .SetRange Range("A2:E" & LastRow)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0