+ Reply to Thread
Results 1 to 8 of 8

ERROR 400 from clicking Macro Button

  1. #1
    Registered User
    Join Date
    08-03-2014
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    37

    Angry ERROR 400 from clicking Macro Button

    Hi I have created a button- which i want to click and allow the rows to sort into a custom order- i have applied VBA and assigned the macro to the button but when I click it comes up with an error that just says "400" it worked for a while when i first put the code in so seems right but now it's not working!

    this is the code i have used.... can you help please

    Sub sortData()

    Dim sh1 As Worksheet
    Dim rSort As Range
    Dim rKey As Range
    Dim customSort(1 To 3) As String
    Set sh1 = ActiveWorkbook.Worksheets("OVERVIEW")

    dataCell = "B10"

    Set rSort = sh1.Range(dataCell).CurrentRegion
    Set rKey = sh1.Range(dataCell)

    customSort(1) = "STATUS"
    customSort(2) = "IN PROGRESS"
    customSort(3) = "COMPLETE"


    Application.AddCustomList ListArray:=customSort
    rSort.Sort Key1:=rKey, Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=Application.CustomListCount + 1, MatchCase:=False, _
    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

    End Sub



    thanks

  2. #2
    Registered User
    Join Date
    08-03-2014
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    37

    Re: ERROR 400 from clicking Macro Button

    actually figured out that it works when the sheet is unprotected!! But when I protect it it comes up with the error?? Any Help?

    Thanks

  3. #3
    Registered User
    Join Date
    01-19-2015
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    59

    Re: ERROR 400 from clicking Macro Button

    Hello,

    When you protect your sheet you can't change cells unless you allow users what activities they can do. I use 2013 Excel but I think you will get the same window (when you try to protect your worksheet) as me where you can mark changes that will be allowed. One of them is "Sort". If you mark it, you should be able to run your macro without getting an error. If it doesn't work, you might unprotect a sheet using VBA code, then use your sorting and finally protect you worksheet again

  4. #4
    Registered User
    Join Date
    08-03-2014
    Location
    Sydney, Australia
    MS-Off Ver
    2010
    Posts
    37

    Re: ERROR 400 from clicking Macro Button

    anyone know VBA code to unprotect, run my sort code, then protect again?

    Thanks

  5. #5
    Registered User
    Join Date
    01-19-2015
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    59

    Re: ERROR 400 from clicking Macro Button

    These methods are as follows:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ERROR 400 from clicking Macro Button

    Maybe
    Please Login or Register  to view this content.
    then
    Please Login or Register  to view this content.
    ??
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  7. #7
    Registered User
    Join Date
    01-19-2015
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    59

    Re: ERROR 400 from clicking Macro Button

    Yes. Of course. Sorry, it's late

  8. #8
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: ERROR 400 from clicking Macro Button

    Sorry rabbit, didn't see that you had already posted to this.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Error opening userform (clicking button)
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-24-2014, 08:10 PM
  2. Error message when clicking on a command button asigned a macro
    By steve123456 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2012, 01:43 AM
  3. [SOLVED] How do I run the macro for a button click without clicking the button?
    By flyboy54 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2012, 10:45 AM
  4. VBA gives "400" error when clicking on a button to run a macro
    By Kaigi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2009, 02:52 PM
  5. how to prevent user from clicking a button on error
    By ballack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2007, 12:17 AM

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.6.0 RC 1