Find blank cells and array items addresses to arraylist

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi Guys, I want to find the cell addresses to a Arraylist (blankarray) of those values in an array (bArray). It seems that the code adds those blank cells' addresses only but not those values to Arraylist. Please advise correction to my code to make it works.
Also I want to list those findings of each row in individual column in the Arraylist (meaning findings of row 3 in rngData shown in column 1 of Arraylist , that of row 4 shown in column 2 of Arraylist and so on).
Thanks.

VBA Code:
Sub rngOver32()

Dim cl As Range, rngData As Range

Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.ScreenUpdating = False


Dim lastrow As Long, lastcol As Long
lastrow = Range("A3").End(xlDown).Row
lastcol = Cells(1, Columns.Count).End(xlToLeft).Column

'LIST OF VALUE TO FIND
Dim bArray As Variant
bArray = Array("AL", "SL", "BL", "CL", "PL", "VL", vbNullString)
Dim bArraystr As String


'EXPORT CELL ADDRESSES TO ARRAYLIST
Dim blankarray As Object
Set blankarray = CreateObject("System.Collections.ArrayList")

'SET DATA RANGE TO SEARCH
Set rngData = Range(Cells(3, 3), Cells(lastrow, lastcol))
Debug.Print rngData.Address

On Error GoTo ErrorHandler

For Each cl In rngData
    If cl.Value = bArraystr Then
       If Not blankarray.contains(cl.Address) Then blankarray.Add cl.Address
    End If
Next cl

ErrorHandler:
Application.EnableEvents = True
   
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

AgentProposal_Roster0728_1025M.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKAL
1MDateAttendance26-Nov27-Nov28-Nov29-Nov30-Nov1-Dec2-Dec3-Dec4-Dec5-Dec6-Dec7-Dec8-Dec9-Dec10-Dec11-Dec12-Dec13-Dec14-Dec15-Dec16-Dec17-Dec18-Dec19-Dec20-Dec21-Dec22-Dec23-Dec24-Dec25-Dec26-Dec27-Dec28-Dec29-Dec30-Dec31-Dec
2DateSummary(5)(4)(3)(2)(1)12345678910111213141516171819202122232425262728293031
3Xia MT:22 L:2.5 D:16.5 E:7 N:0GGGGGGVLVLGGDKEEEDDDDDAMDDDDDDEEEE
4Zita VT:22 L:1 D:12 E:11 N:0DDDDDDDEEEEEDDDDDDDDCLEEEEEE
5Ken CT:22 L:6 D:5 E:5 N:11KKKKKKKKALNNNNNEEEEEALNNNNNNALALALAL
6Larry QT:22 L:0 D:15 E:0 N:0D3D3D3D3D3D3D3D4D4D4D4D4D4D4D4D4D4G
7John GT:22 L:0.5 D:17.5 E:5 N:0EEEEEEED1D1D1GGGGGPMGGGGGGGGG
202112
Cells with Data Validation
CellAllowCriteria
A3:A7List=HelpAgent
H3:AL7List=ShiftcodeNew
A1List=Data!$U$2:$U$15
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You are not checking all the values in Barray, Try this small modification, not necesarily the fastest way of doing this.
VBA Code:
Sub rngOver32()

Dim cl As Range, rngData As Range

Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.ScreenUpdating = False


Dim lastrow As Long, lastcol As Long
lastrow = Range("A3").End(xlDown).Row
lastcol = Cells(1, Columns.Count).End(xlToLeft).Column

'LIST OF VALUE TO FIND
Dim bArray As Variant
bArray = Array("AL", "SL", "BL", "CL", "PL", "VL", vbNullString)
Dim bArraystr As String


'EXPORT CELL ADDRESSES TO ARRAYLIST
Dim blankarray As Object
Set blankarray = CreateObject("System.Collections.ArrayList")

'SET DATA RANGE TO SEARCH
Set rngData = Range(Cells(3, 3), Cells(lastrow, lastcol))
Debug.Print rngData.Address

On Error GoTo ErrorHandler
For i = 1 To UBound(bArray)
bArraystr = bArray(i)
For Each cl In rngData
    If cl.Value = bArraystr Then
       If Not blankarray.contains(cl.Address) Then blankarray.Add cl.Address
    End If
Next cl
Next i
ErrorHandler:
Application.EnableEvents = True
   
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Hi offthelip,
It seems working. Can I add below code to output the findings to columns in another worksheet to review ?
(There are 5 rows of data to be listed in 5 columns in blankarray)

Dim blankarray_result As Variant
blankarray_result = blankarry.toarray

'Export Findings to Sheets("Data") Z Column
Sheets("Data").Range("Z1:Z" & Sheets("Data").Range("Z1").End(xlDown).Row).ClearContents
Sheets("Data").Range("Z1").Resize(UBound(blankarray_result) + 1, 1).Value = Application.Transpose(blankarray_result)
 
Upvote 0
Can I add below code to output the findings to columns in another worksheet to review ?
(There are 5 rows of data to be listed in 5 columns in blankarray)
I don't ever use collections since I always use dictionaries instead. So I can't help you with any syntax you need to write out your collection.
 
Upvote 0
Hi offthetop , what the code should be if using dictionaries to meet my goal.
 
Upvote 0
I wouldn't actually use a dictionary to do what I think you are trying to do, I would just use variant arrays, like this:
VBA Code:
Sub rngOver32()

'Dim cl As Range,
Dim rngData As Variant

'Application.DisplayStatusBar = False
'Application.EnableEvents = False
'Application.ScreenUpdating = False
' Not necesary since we are not triggering events or updating the worksheet

Dim lastrow As Long, lastcol As Long
lastrow = Range("A1").End(xlDown).Row
lastcol = Cells(1, Columns.Count).End(xlToLeft).Column

'LIST OF VALUE TO FIND
Dim bArray As Variant
bArray = Array("AL", "SL", "BL", "CL", "PL", "VL", vbNullString)
Dim bArraystr As String




Dim blankarray() As Variant

ReDim blankarray(1 To lastrow * lastcol, 1 To 1)
'Load DATA RANGE TO SEARCH
rngData = Range(Cells(1, 1), Cells(lastrow, lastcol)) ' this load the data into a variant array (much faster)


'On Error GoTo ErrorHandler don't do this it just hides any error
indi = 1
For i = 1 To UBound(bArray)
bArraystr = bArray(i)
 For j = 3 To lastrow ' Note we are starting on row 3 as per the original
   For k = 3 To lastcol
    If rngData(j, k) = bArraystr Then
       blankarray(indi, 1) = colno2let(k) & j
       indi = indi + 1
    End If
   Next k
 Next j
Next i
With Worksheets("sheet2")
 .Range(.Cells(1, 1), .Cells(indi - 1, 1)) = blankarray
'ErrorHandler:
End With
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub


Function colno2let(colno As Variant) As String
let2 = colno / 26
If let2 > 1 Then
 let22 = Round(let2)
 txt = Chr(let22 + 64)
 txt = txt & Chr(64 + colno - (26 * let22))
Else
txt = Chr(colno + 64)
End If
colno2let = txt

End Function
Note the colno2let function only works up to column ZZ
Note however I don't know why you want a list of addresses on a worksheet, this can't be the ultimate goal
 
Upvote 0
Hi offthelip, I got this error when running the code. I just want to review the blankarray result in column AA in worksheet named "Data".
Your advice in Post #2 seems working but I just want to see the output result (this is just for my learning only and not necessary in actual execution of the marco).
Yes, your curiosity is right. My ultimate goal is to find if those cells which fall in bArray conditions' column displacement is more than five, then highlight those cells in between them.
I attach the expected blankarray list's image and from that count the displacement between T3 and M3 (col 20 - col 13 -1=6) then applying the result to active worksheet to highlight cells between S3 to N3, so does the cells between AH3 and Z3 where cells AG3:AA3 in active worksheet will be highlighted and so does the other rows and columns .......
Appreciate your advice. Thanks.
 

Attachments

  • error in 33.png
    error in 33.png
    24.7 KB · Views: 11
  • blankarray expectation.png
    blankarray expectation.png
    17.5 KB · Views: 10
  • Inkedarea to highlight_XX.jpg
    Inkedarea to highlight_XX.jpg
    86 KB · Views: 8
Upvote 0
I have no idea why you are getting an error. when I run the code on the data you posted in post#1 it runs perfectly, and produces a list of address in column A of sheet2 : this is the start of the list:

AE4
I3
J3
L3
M3
T3
Z3
AH3
D4
E4
I4
 
Upvote 0
Hi, what should be changed if I want the result to be viewed in sheet "Data" column AA
 
Upvote 0
change:
VBA Code:
With Worksheets("sheet2")
to
VBA Code:
With Worksheets("Data")
i.e. your change looks correct.
When or if you get an error check what the value in "indi" is
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top