• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Create dynamic array conditionally

tomas

Active Member
Hi

My apology for not trying it myself cause shortage of time.

Anyways in column A I have a list of IDs In VBA I want to create dynamic ARRAY which will populate with numbers from column A which are bolded

Thanks for helping out
 

Attachments

  • example.xlsx
    10.2 KB · Views: 2
Try this:
Code:
Sub AddBoldtoArray()
Dim cell As Range
Dim tRng As Range
Dim fRng As Range
Dim lRow, i As Long
Dim myArr()

On Error Resume Next

lRow = Cells(Rows.Count, 1).End(xlUp).Row
Set tRng = ThisWorkbook.Sheets(1).Range("A1:A" & lRow)

For Each cell In tRng
    If cell.Font.Bold Then
        If fRng Is Nothing Then
            Set fRng = cell
        Else
            Set fRng = Union(fRng, cell)
        End If
    End If
Next
If Not fRng Is Nothing Then
    i = 0
    ReDim Preserve myArr(fRng.Cells.Count - 1)
    For Each cell In fRng
        myArr(i) = cell.Value
        i = i + 1
    Next
End If

End Sub
 
Back
Top