' Ensure strict type conversion
Dim groupedData As Dictionary(Of String, DataTable) = InputDt.AsEnumerable() _
.GroupBy(Function(row) (row("Company").ToString)) _
.ToDictionary(Function(g) (g.Key), Function(g) g.CopyToDataTable())
' Initialize the output dictionary
GroupedDataTables = New Dictionary(Of String, DataTable)()
' Add each group to the dictionary
For Each kvp In groupedData
GroupedDataTables.Add(kvp.Key, kvp.Value)
Next
=> Use For Each loop to iterate through GroupedDataTables
For Each currentKeyValuePairOfTextAndDataTable in GroupedDataTables
Write Range Workbook -> pass datatable as currentKeyValuePairOfTextAndDataTable
Assign -> Count = Count + 1
End For Each