I. Introduction
In the past, chatgpt was mainly used for Q&A. This time I joined the planet and learned how to use chatgpt to process Excel. Although it is not very convenient to handle it now, it will be faster and faster when I am familiar with it (mainly familiar with the prompt words).
Two preparations
An available chatgpt account, or a test account that has passed the new bing application. Other conditions:
The browser uses Edge.
Installed the Mod Header plug-in and configured the X-Forwarded-For value to be 8.8.8.8
Science is online, and the location information of the browser is prohibited.
Install the Edge plug-in chattonai, which is chatgpt in Chinese. I used to be unable to access chatgpt even if I surfed the Internet scientifically. By clicking this plug-in to jump to the chatgpt homepage, it turned out to be ok, and I could log in normally.
Three preparation data
Because my new version of Edge had problems installing many times, I tried a lot of methods, but I couldn’t install it. Finally, I used the bing robot using skype. I feel that the effect of this robot is similar to that of skype.
Let it prepare some data for us:
Copy data into Excel:
4. Use AI to help us do something
4.1 Basic formula
If we need to sum all salaries, but forget the sum formula, we can ask it: the result is as follows:
If you want to check the basic salary on Saturday, you can ask Bing for the specific Excel formula:
Paste the formula in:
5. Do something more complicated
We know that in Excel, VBA scripts can complete more complex operations. If we need to set the title to red, set each odd-numbered row below to blue, and even-numbered rows to light blue. Set the prompt words according to our requirements: "Write VBA, set the first row from column A to column F to red, start from the second row to set the odd-numbered rows to blue, and the even-numbered rows to light blue"
5.1 Set table style VBA script
Ask bing how to write this VBA, but did not tell us how to create a new VBA, etc., you can ask chatgpt to see if you can return the order in more detail:
Continue to ask how to create a new one:
Follow the prompts to operate, after pasting the vba script, click to run:
After closing the window, press Alt+F8 to select our newly created macro, the application effect: I found something wrong, why the following lines are all set to red, and re-change the prompt word to ask: "When writing VBA, the first line Set columns A to F to red, and from the second to the last row, set the odd rows to blue and the even rows to light blue"
仍然不对:在更改提示词询问:" When writing VBA, set the background color of the first row A to F to red; from the second row to the last row, set the background color of odd rows to blue, set the background color of even rows to light blue, and do not set it if there is no data in this row."
The vba script provided this time is no problem:
Sub FormatRows()
Dim lastRow As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row 'get last row with data
'set format for first row
Range("A1:F1").Interior.Color = RGB(255, 0, 0) 'set red color for columns A to F in row 1
'set format for odd and even rows with data
For i = 2 To lastRow 'loop through rows with data
If WorksheetFunction.CountA(Range("A" & i & ":F" & i)) > 0 Then 'check if row has data
If i Mod 2 = 0 Then 'check if row number is even
Range("A" & i & ":F" & i).Interior.Color = RGB(135, 206, 235) 'set light blue color for columns A to F in even rows
Else 'row number is odd
Range("A" & i & ":F" & i).Interior.Color = RGB(153, 204, 255) 'set blue color for columns A to F in odd rows
End If
End If
Next i
End Sub
5.2 vba script for generating statistical graphs
Prompt words: "Write a VBA program, the data ranges from C2 to C17, and generate a histogram in the current workspace, including an interval from 5,000 to 10,000, an interval from 10,000 to 15,000, and an interval above 15,000. The title of the histogram is basic salary Statistics" bing given the vba script:
您好,您可以使用以下代码来生成柱状图:
Sub CreateChart()
Dim MyChart As Chart
Set MyChart = ActiveSheet.Shapes.AddChart2(251, xlColumnClustered).Chart
MyChart.SetSourceData Source:=Range("C2:C17")
MyChart.HasTitle = True
MyChart.ChartTitle.Text = "基本工资统计"
MyChart.Axes(xlCategory).TickLabels.NumberFormatLocal = "0.00"
MyChart.Axes(xlValue).TickLabels.NumberFormatLocal = "0.00"
MyChart.Axes(xlValue).MinimumScale = 5000
MyChart.Axes(xlValue).MaximumScale = 15000
MyChart.Axes(xlValue).MajorUnit = 5000
End Sub
这段代码将数据范围C2到C17的数据生成柱状图,并将5000到10000,10000到15000,15000以上作为三个区间。柱状图的标题为“基本工资统计”。要执行此VBA,请按下Alt + F11打开Visual Basic Editor,然后在左侧的“项目资源管理器”窗格中选择要更改的工作簿。然后,单击“插入”菜单上的“模块”,并将代码复制到新模块
Note that the double quotes in the code are all written as "need to be escaped, the result is wrong:
After many attempts, the final effect is finally completed through chatgpt: Prompt words: "Write a VBA program, where C is the base salary, and the range of the base salary is calculated. The data of the base salary is the data from C2 to C17, and a columnar column is generated in the current workspace. Fig. Divided into 3 intervals at the same time, the intervals range from 5,000 to 10,000, 10,000 to 15,000, and above 15,000. Note that no data can be changed” English prompt words:
Write VBA program, in which C lists the base salary, statistics the range of the base salary, the basic salary data is C2 to C17 data, in the current work area to generate a bar chart. At the same time, it is divided into three intervals, which range from 5000 to 10,000 to 15000 and above. Note that no data can be changed.
I translated the tips from Chinese to English. It is said that asking questions in Chinese is easier to get your account blocked. The final result is as follows:
Sub GenerateSalaryChart()
'Declare variables
Dim wb As Workbook
Dim ws As Worksheet
Dim salaryRange As Range
Dim salaryData As Variant
Dim lowRange As Long
Dim medRange As Long
Dim highRange As Long
Dim salaryCount(2) As Integer
Dim i As Long
'Set the workbook and worksheet
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet
'Set the salary range
Set salaryRange = ws.Range("C2:C17")
salaryData = salaryRange.Value
'Set the intervals
lowRange = 5000
medRange = 10000
highRange = 15000
'Loop through the data and count the number of salaries in each interval
For i = LBound(salaryData) To UBound(salaryData)
If salaryData(i, 1) >= lowRange And salaryData(i, 1) <= medRange Then
salaryCount(0) = salaryCount(0) + 1
ElseIf salaryData(i, 1) > medRange And salaryData(i, 1) <= highRange Then
salaryCount(1) = salaryCount(1) + 1
ElseIf salaryData(i, 1) > highRange Then
salaryCount(2) = salaryCount(2) + 1
End If
Next i
'Create a new chart and set the chart type to column chart
Dim chartObj As ChartObject
Set chartObj = ws.ChartObjects.Add(Left:=250, Width:=400, Top:=10, Height:=250)
chartObj.Chart.ChartType = xlColumnClustered
'Set the chart title
chartObj.Chart.HasTitle = True
chartObj.Chart.ChartTitle.Text = "Basic Wage Statistics"
'Add the data series to the chart
Dim chartSeries As Series
Set chartSeries = chartObj.Chart.SeriesCollection.NewSeries
chartSeries.Name = "Salary"
chartSeries.Values = salaryCount
'Set the axis labels and tick marks
With chartObj.Chart.Axes(xlCategory, xlPrimary)
.CategoryNames = Array("5000-10000", "10000-15000", ">15000")
.TickLabels.NumberFormat = "0"
End With
End Sub
Six summary
Through the above series of examples, I feel that the prompt words are very important. If the method of asking is wrong and not accurate enough, there may be some problems in the answer provided to you. It must be clear and concise. Maybe I use the normal version of chatgpt , the plus version may be more powerful.
For chatgpt, the scope of application is getting wider and wider, and different ways of playing are also seen in Knowledge Planet and Geek Time, such as generating mind maps, summarizing documents, answering questions based on the information you provide, and this In the introduction of processing Excel data, more and more people have seen the power of chatgpt. What's more frightening is that it is still evolving. If you can't beat it, just join. Those who gradually master chatgpt will become ten times more efficient workers. Coupled with some good ideas, it should be good to use chatgpt to start a wave of entrepreneurship.