+ Reply to Thread
Results 1 to 7 of 7

Using ChatGPT for VBA

  1. #1
    Forum Contributor
    Join Date
    02-25-2022
    Location
    Dallas, Texas
    MS-Off Ver
    Office 365
    Posts
    174

    Using ChatGPT for VBA

    I was experimenting with ChatGPT and I thought I would try some VBA questions. It did surprising well. As an example I asked this question:

    Need a sort algorithm in VBA


    Here is an example of a simple sorting algorithm in VBA (Visual Basic for Applications) that uses the Bubble sort method:

    Please Login or Register  to view this content.
    This algorithm takes an array of values as input and sorts the values in ascending order. The outer loop runs from 0 to n-1, and the inner loop runs from 0 to n-i-1. In each iteration of the inner loop, the algorithm compares the current value with the next value in the array. If the current value is greater than the next value, the algorithm swaps the two values. This process is repeated until the entire array is sorted.

    You can use the above function by passing an array to it like this:

    Please Login or Register  to view this content.
    Note that, this is a basic sorting algorithm, there are more efficient sorting algorithms like quicksort, mergesort, heapsort that can be used depending on the size of the array and the needs of the application.

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Using ChatGPT for VBA

    I also recently "talked" to this "intelligence" about VBA. Unfortunately, he makes a lot of mistakes, using, for example, constants that do not exist in VBA. I get the impression that he relies more on classic VB as on VBA. In several topics he was unable to find a solution. Maybe I showed too little patience in trying to improve his suggestions.
    Overall, a nice tool, but you have to "watch his hands".

    Artik

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Using ChatGPT for VBA

    I've actually managed to successfully develop about 12 different python projects from scratch using ChatGPT for the entire code. Even when the code didn't work, I was able to go back and say "I get this error", it re-evaluates the code it originally gave me and in most instances it is able to find its mistake and fix it.

    But as Artik mentioned, it did struggle a little with VBA, as if it's not able to tell the difference between VB and VBA. I think if they had given it a bit more data to work from, most of the inconsistencies could be ironed out.

  4. #4
    Forum Contributor
    Join Date
    02-25-2022
    Location
    Dallas, Texas
    MS-Off Ver
    Office 365
    Posts
    174

    Re: Using ChatGPT for VBA

    From what I tried it worked for simple requests so if you can break your problem into small requests it seems to work ok.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: Using ChatGPT for VBA

    I did some experiments too, and my general impression is, that by using it as a tool to write "a sketch" of the solution to well descripted classical problem, and then correcting it myself, it can be time-saving method.
    I also tried to discuss and ask for corrections (sometimes it was like with my students: I ask about something, and student answers on similar, but different question, he/she knows the answer).
    It worked too. So I could say, I could benefit from it.

    On the other hand, I expect that for less experienced person the code (except of really the easiest cases) would need qualified human work to be really valid.

    And let's remember it is a general system. I expect that the one trained in a narrow field (perhaps one programming language, may be also certain class of problems) could perform signifficantly better already nowadays. And also let's note that the progress in this field is very quick.
    Best Regards,

    Kaper

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Using ChatGPT for VBA

    Quote Originally Posted by Kaper View Post
    I expect that for less experienced person the code (except of really the easiest cases) would need qualified human work to be really valid.
    That's why it's currently banned from Stack Overflow. All too often it produces code that looks plausible, but either doesn't work at all, or does something that is not what it was asked.
    Rory

  7. #7
    Valued Forum Contributor
    Join Date
    01-07-2022
    Location
    Europe
    MS-Off Ver
    Office 365
    Posts
    473

    Re: Using ChatGPT for VBA

    I've done some testing on it too, it's been quite impressive for simple tasks such as creating basic UDFs. Sometimes it overcomplicates things though on the first try, and asking it to minimise the code can be quite effective.

    For those having issues with it distinguishing between VB and VBA, have you explicitly mentioned that it's for Excel in your request?
    <<< If you have valued anyone's contributions in this thread, please click * to thank them for their efforts

+ Reply to Thread

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