Sub CreatePieChartsFromTextColumns(nSht as Integer) Dim wsData As Worksheet, wsChart As Worksheet Dim lastCol As Long, lastRow As Long Dim col As Long, row As Long, i as Long Dim cellValue As String, header As String Dim dict As Object Dim chartCount As Long Dim chartLeft As Double, chartTop As Double Dim chartWidth As Double, chartHeight As Double Set wsData = Worksheets(nSht) ' Determine last column and row lastCol = wsData.Cells(1, wsData.Columns.Count).End(xlToLeft).Column lastRow = wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row ' Create or clear 'pie_charts' sheet On Error Resume Next Set wsChart = ThisWorkbook.Sheets("pie_charts") If wsChart Is Nothing Then Set wsChart = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets( _ ThisWorkbook.Sheets.Count)) wsChart.Name = "pie_charts" Else wsChart.Cells.Clear wsChart.ChartObjects.Delete End If On Error GoTo 0 chartCount = 0 chartWidth = 500 chartHeight = 500 chartLeft = 20 chartTop = 20 ' Loop through each column in header For col = 1 To lastCol header = wsData.Cells(1, col).Value Set dict = CreateObject("Scripting.Dictionary") Dim isTextOnly As Boolean isTextOnly = True ' Scan all rows in this column For row = 2 To lastRow cellValue = wsData.Cells(row, col).Value If cellValue <> "" Then ' Check if value is numeric If IsNumeric(cellValue) Then isTextOnly = False Exit For End If ' Add to dictionary for uniqueness If Not dict.exists(cellValue) Then dict.Add cellValue, 1 Else dict(cellValue) = dict(cellValue) + 1 End If End If Next row Dim maxValue As Variant, currentItem As Variant For Each currentItem In dict.Items If currentItem > maxValue Then maxValue = currentItem End If Next currentItem ' Check if more than 5 unique categories and only text If isTextOnly And dict.Count > 5 and dict.Count < 20 and maxValue > 2 Then ' Output frequency to temporary range in chart sheet Dim startRow As Long startRow = wsChart.Cells(wsChart.Rows.Count, 1).End(xlUp).Row + 2 If startRow < 2 Then startRow = 2 wsChart.Cells(startRow - 1, 1).Value = header i = 0 For Each key In dict.Keys wsChart.Cells(startRow + i, 1).Value = key wsChart.Cells(startRow + i, 2).Value = dict(key) i = i + 1 Next key ' Insert chart chartLeft = (chartCount Mod 3) * (chartWidth + 20) chartTop = Int(chartCount / 3) * (chartHeight + 20) Dim chartObj As ChartObject Set chartObj = wsChart.ChartObjects.Add(Left:=chartLeft, Top:=chartTop, _ Width:=chartWidth, Height:=chartHeight) chartObj.Chart.ChartType = xlPie chartObj.Chart.SetSourceData Source:=wsChart.Range(wsChart.Cells(startRow, 1), _ wsChart.Cells(startRow + dict.Count - 1, 2)) chartObj.Chart.HasTitle = True chartObj.Chart.ChartTitle.Text = header chartCount = chartCount + 1 End If Set dict = Nothing Next col Worksheets("pie_charts").Cells.ClearContents MsgBox chartCount & " pie charts created in 'pie_charts' sheet.", vbInformation End Sub