In column A, I have many strings ~ 32000 cells each containing unique string values. I then have columns C to as many as 30/40 columns which all contain approximately 400 rows of text.
- Check column (j) for any text not present in column A
- If true then add new string to column A
- Run comparison of Column A against column (j)
- If a match is found then place a checkmark in the corresponding column (j) for the row where the string is found
However the problem is that this can take up to 7 or 8 minutes for 10 columns of data. This is far too long and surely there is a faster way to run this comparison?
Sub AddSignals()
Dim rng1 As Range, rng2 As Range, i As Long, iL As Long, id As Long, idL As Long, var As Range, var2 As Range, j As Long, ws1 As Worksheet, ws2 As Worksheet, jL As Long, rng5 As Range, jFn As Long, iLs As Long, iLss As Range, rng1s As Range, rng2s As Range
Dim rng3 As Range, rng4 As Range, lCols As Long, lRows As Long, SrtRng As Range, Acell As Range, iLs2 As Long, iLss2 As Range, SrtRngF As Range, AcellF As Range
Dim Clnup As Range, Clncol As Long, ClnRow As Long, trimrng As Range, trimrng1 As Range, emptyrange As Range, EmptyCol As Long
On Error GoTo ErrHandler
Set ws1 = Sheet7
Set ws2 = Sheet2
'Look for new signals and add to sigal list
jL = ws1.Cells(7, Columns.Count).End(xlToLeft).Column
For j = 3 To jL
'Set range limits
jF = ws2.Cells(7, Columns.Count).End(xlToLeft).Column
jFn = jF + 1
ws2.Cells(7, jFn).Value = ws1.Cells(7, j).Value
idL = ws1.Cells(Rows.Count, j).End(xlUp).Row
For id = 8 To idL
'iLs = ws1.Cells(Rows.Count, 1).End(xlUp).Row
iLs2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row
'Set iLss = ws1.Cells(iLs + 1, 1)
Set iLss2 = ws2.Cells(iLs2 + 1, 1)
Set rng1s = ws1.Cells(id, j)
If Not IsEmpty(rng1s) Then
Set rng2s = ws2.Range(ws2.Cells(7, 1), ws2.Cells(ws2.Cells(Rows.Count, 1).End(xlUp).Row, 1))
Set var2 = rng2s.Find(rng1s.Value, LookIn:=xlValues, LookAt:=xlWhole)
If var2 Is Nothing Then
bln = True
If bln = True Then
'rng1s.Interior.Color = RGB(255, 255, 0)
'iLss.Value = rng1s.Value
iLss2.Value = rng1s.Value
' iLss.SpecialCells (xlCellTypeConstants)
'remove any spaces from cells
' iLss.Value = WorksheetFunction.Trim(iLss.Value)
iLss2.SpecialCells (xlCellTypeConstants)
iLss2.Value = WorksheetFunction.Trim(iLss2.Value)
Set emptyrange = ws2.Range(ws2.Cells(iLss2.Row, 2), ws2.Cells(iLss2.Row, jF))
For Each cell In emptyrange
If IsEmpty(cell) Then
cell.Font.Name = "Wingdings"
cell.Value = ChrW(&HFB)
cell.Interior.Color = RGB(157, 153, 156)
End If
Next cell
Else
End If
End If
End If
Next id
'Removes any spaces from cells
'Set trimrng1 = ws2.Range(ws2.Cells(8, 1), ws2.Cells(iLs, 1))
'For Each cell In trimrng1.SpecialCells(xlCellTypeConstants)
'cell.Value = WorksheetFunction.Trim(cell.Value)
'Next cell
'Sort signal list in alphabetical order (in draft sheet)
'SrtRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
'SrtCol = ws1.Cells(7, Columns.Count).End(xlToLeft).Column
'Set SrtRng = ws1.Range(ws1.Cells(7, 1), ws1.Cells(SrtRow, SrtCol))
'Set Acell = ws1.Range("A7")
'SrtRng.Sort key1:=Acell, order1:=xlAscending, Header:=xlYes
'Sort signal list in alphabetical order (in measurement database sheet)
SrtRowF = ws2.Cells(Rows.Count, 1).End(xlUp).Row
SrtColF = ws2.Cells(7, Columns.Count).End(xlToLeft).Column
Set SrtRngF = ws2.Range(ws2.Cells(7, 1), ws2.Cells(SrtRowF, SrtColF))
Set AcellF = ws2.Range("A7")
SrtRngF.Sort key1:=AcellF, order1:=xlAscending, Header:=xlYes
iL = ws2.Range("A" & Rows.Count).End(xlUp).Row
ws2.Columns(jFn).AutoFit
'Run comparison of each measurement file one by one
Set rng2 = ws1.Range(ws1.Cells(7, j), ws1.Cells(ws1.Cells(Rows.Count, j).End(xlUp).Row, j))
For i = 8 To iL
Set rng1 = ws2.Range("A" & i)
Set rng5 = ws2.Cells(i, jFn)
Set var = rng2.Find(rng1.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not var Is Nothing Then
'rng1.Interior.Color = RGB(255, 255, 0)
'rng2.Interior.Color = RGB(255, 100, 100)
rng5.Font.Name = "Wingdings"
rng5.Value = ChrW(&HFC)
rng5.Interior.Color = RGB(6, 232, 49)
Else
rng5.Font.Name = "Wingdings"
rng5.Value = ChrW(&HFB)
rng5.Interior.Color = RGB(157, 153, 156)
End If
Next i
Next j
'Cleanup final sheet
ClnRow = ws2.Cells(Rows.Count, 1).End(xlUp).Row
Clncol = ws2.Cells(7, Columns.Count).End(xlToLeft).Column
Set Clnup = ws2.Range(ws2.Cells(7, 2), ws2.Cells(ClnRow, Clncol))
Clnup.VerticalAlignment = xlCenter
Clnup.HorizontalAlignment = xlCenter
'Clear draft sheet
lRows0 = ws1.Cells(Rows.Count, "A").End(xlUp).Row
lCols0 = ws1.Cells(7, Columns.Count).Column
Set rng = ws1.Range(ws1.Cells(7, 2), ws1.Cells(lRows0, lCols0))
rng.ClearContents
ws2.Rows(7).Font.Name = "Calibri"
Call Meas_Info
ErrHandler:
Sheet1.Protect Password:="abc"
Sheet2.Protect Password:="abc"
Sheet3.Protect Password:="abc"
Sheet5.Protect Password:="abc"
Sheet6.Protect Password:="abc"
Sheet7.Protect Password:="abc"
Sheet8.Protect Password:="abc"
Sheet5.Visible = xlSheetVeryHidden
Sheet6.Visible = xlSheetVeryHidden
Sheet7.Visible = xlSheetVeryHidden
Sheet8.Visible = xlSheetVeryHidden
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
End If
Exit Sub
End Sub
bln = True: If bln = True Then
intended to do and why does it come with an emptyElse
clause? \$\endgroup\$