Excel’s version of a word cloud, which is also known as a tag cloud, is a graphical representation of text that may be formatted or colored in a variety of ways. The size of the typeface used to represent a word in a word cloud corresponds to the amount of times that word appears in the cloud. Excel’s SmartArt and forms features were utilized in its production.
In Excel, what exactly is a Word Cloud?
Excel’s “word cloud” feature is a collection of words that may be shown in the form of a visualization. We hope that you have seen some of the most impressive dashboards that Excel has to offer, complete with data and imaginative visualizations. There is a wide variety of cool items that can be found on dashboards, from elegant typefaces to appealing color schemes. Surely you’ve come across at least one of those weird dashboards with a “Word Cloud.” Excel Visual Basic for Applications (VBA) was used to generate the image, despite the appearance of being a sophisticated software image that was obtained from somewhere else. Yes! You are accurate. The VBA programming language was used to develop it. Excel will be used to demonstrate how to generate a word cloud similar to the one described in this article.
Excel: How to Generate a “Word Cloud”
Excel requires that we have data on words and an idea of what colors should be used for each word before it will allow us to generate a word cloud. Let’s say you want to create a word cloud out of 30 different Excel formulae. Therefore, within the Excel worksheet, compile a list of thirty different formulae.
Copy and paste the formulae shown above into the first column of your worksheet.
After you have written the names of the aforementioned formulas in column B, use the RANDBETWEEN function for all 30 of the entries. The following are the formulas: Don’t change the top value of 250 or the bottom value of 1.
After ensuring that the data is accurate, we will then proceed to the Visual Basic Editor. To begin, use VBA to design a user form similar to the one shown below.
Now, in this section of the VBA code, we need to configure the userform. We need to develop code for each button individually. The code for each button may be seen below.
You may add the following code by double-clicking the “Different Colors” button on the user form that is located above.
Private Sub CommandButton1_Click() ColorCopeType = 0 Unload Me 'This is for a different color End Sub
After that, perform a double click on the button that’s black, and then add the code that’s below.
Private Sub CommandButton2_Click() ColorCopeType = 1 Unload Me 'This is for black color End Sub
Add the following codes to each of the other buttons, just as you did before.
Private Sub CommandButton3_Click() ColorCopeType = 2 Unload Me 'This is for red color End Sub Private Sub CommandButton4_Click() ColorCopeType = 3 Unload Me 'This is for green color End Sub Private Sub CommandButton5_Click() ColorCopeType = 4 Unload Me 'This is for blue color End Sub Private Sub CommandButton6_Click() ColorCopeType = 5 Unload Me 'This is for yellow color End Sub Private Sub CommandButton7_Click() ColorCopeType = 6 Unload Me 'This is for white color End Sub
After we have configured the code, the first thing that we need to do is declare the variable for the module.
Now comes the time-consuming task of writing the programming necessary to generate a word cloud. The code may be found below.
Sub word_cloud() Dim WordCloud As Range Dim x As Integer, y As Integer Dim ColumnA As Range, ColumnB As Range Dim WordCount As Integer Dim ColumCount As Integer, RowCount As Integer Dim WordColumn As Integer, WordRow As Integer Dim plotarea As Range, c As Range, d As Range, e As Range, f As Range, g As Range Dim z As Integer, w As Integer Dim plotareah1 As Range, plotareah2 As Range, dummy As Range Dim q As Integer, v As Integer Dim RedColor As Integer, GreenColor As Integer, BlueColor As Integer UserForm1.Show WordCount = -1 Set WordCloud = Sheets("Word Cloud").Range("B2:H7") ColumnCount = WordCloud.Columns.Count RowCount = WordCloud.Rows.Count For Each ColumnA In Sheets("Formula List").Range("A:A") If ColumnA.Value = "" Then Exit For Else WordCount = WordCount + 1 End If Next ColumnA Select Case WordCount Case WordCount = 0 To 20 WordColumn = WordCount / 5 Case WordCount = 21 To 40 WordColumn = WordCount / 6 Case WordCount = 41 To 40 WordColumn = WordCount / 8 Case WordCount = 80 To 9999 WordColumn = WordCount / 10 End Select WordRow = WordCount / WordColumn x = 1 Set c = Sheets("Word Cloud").Range("A1").Offset((RowCount / 2 - WordRow / 2), (ColumnCount / 2 - WordColumn / 2)) Set d = Sheets("Word Cloud").Range("A1").Offset((RowCount / 2 + WordRow / 2), (ColumnCount / 2 + WordColumn / 2)) Set plotarea = Sheets("Word Cloud").Range(Sheets("Word Cloud").Cells(c.Row, c.Column), Sheets("Word Cloud").Cells(d.Row, d.Column)) For Each e In plotarea e.Value = Sheets("Formula List").Range("A1").Offset(x, 0).Value e.Font.Size = 8 + Sheets("Formula List").Range("A1").Offset(x, 0).Offset(0, 1).Value / 4 Select Case ColorCopeType Case 0 RedColor = (255 * Rnd) + 1 GreenColor = (255 * Rnd) + 1 BlueColor = (255 * Rnd) + 1 Case 1 RedColor = 0 GreenColor = 0 BlueColor = 0 Case 2 RedColor = 255 GreenColor = 0 BlueColor = 0 Case 3 RedColor = 0 GreenColor = 255 BlueColor = 0 Case 4 RedColor = 0 GreenColor = 0 BlueColor = 255 Case 5 RedColor = 255 GreenColor = 255 BlueColor = 100 Case 6 RedColor = 255 GreenColor = 255 BlueColor = 255 End Select e.Font.Color = RGB(RedColor, GreenColor, BlueColor) e.HorizontalAlignment = xlCenter e.VerticalAlignment = xlCenter x = x + 1 If e.Value = "" Then Exit For End If Next e plotarea.Columns.AutoFit End Sub
The code for your module may be copied and pasted from up above. For instance, the worksheet that contains a formula list ought to be referred to as the “Formula List.” After that, create a new worksheet in Excel and call it the “Word Cloud” worksheet.
In the new sheet that was just entered, reduce the zoom to 40 percent and increase the row height to 85.
The next step is to hit the F5 button to run the code that was created in VBA. You will be presented with the user form that allows you to select colors.
Pick the hue that best suits your preferences. Choose “Different Colors” if you do not want a single color to appear on your product. After then, the “Word Cloud” sheet will be updated with the word cloud.
Using this method, which involves coding in VBA, we can generate a word cloud.
1 Comment