Hiya. I am having fun learning this vba stuff! But, I'm stuck.
My Book contains businesses and address info, like this:
<style>table { }tr { }col { }br { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: black; font-size: 12pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; vertical-align: bottom; border: medium none; white-space: nowrap; }.xl65 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl66 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl67 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl68 { border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl69 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl70 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl71 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl72 { border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; }.xl73 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; }.xl74 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; }.xl75 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; }.xl76 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl77 { text-align: center; }</style> [TABLE="width: 923"]
<tbody>[TR]
[TD="width: 17"][/TD]
[TD="class: xl77, width: 87"]A[/TD]
[TD="class: xl77, width: 87"]B[/TD]
[TD="class: xl77, width: 87"]C[/TD]
[TD="class: xl77, width: 87"]D[/TD]
[TD="class: xl77, width: 87"]E[/TD]
[TD="class: xl77, width: 87"]F[/TD]
[TD="class: xl77, width: 87"]G[/TD]
[TD="class: xl77, width: 87"]H[/TD]
[TD="class: xl77, width: 87"]I[/TD]
[TD="class: xl77, width: 87"]J[/TD]
[TD="class: xl77, width: 87"]K[/TD]
[TD="class: xl77, width: 87"]L[/TD]
[TD="class: xl77, width: 87"]M[/TD]
[TD="class: xl77, width: 87"]N[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="class: xl65"]BureauNumber[/TD]
[TD="class: xl66"]Primary Name[/TD]
[TD="class: xl66"]Street Address[/TD]
[TD="class: xl66"]City[/TD]
[TD="class: xl66"]Zip Code[/TD]
[TD="class: xl66"]State[/TD]
[TD="class: xl66"]County[/TD]
[TD="class: xl66"]Governing Class[/TD]
[TD="class: xl66"]Description[/TD]
[TD="class: xl66"]ExMod[/TD]
[TD="class: xl66"]Updated On[/TD]
[TD="class: xl66"]ExModYear[/TD]
[TD="class: xl66"]InsurerName[/TD]
[TD="class: xl67"]CoverageDate[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="class: xl68, align: right"]3484[/TD]
[TD="class: xl69"]M P A SALES, INC.[/TD]
[TD="class: xl69"]13700 VAN NESS AVENUE[/TD]
[TD="class: xl69"]GARDENA[/TD]
[TD="class: xl69, align: right"]90249[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]Los Angeles County[/TD]
[TD="class: xl69, align: right"]8018[/TD]
[TD="class: xl69"]STORES-WHOLESALE[/TD]
[TD="class: xl69, align: right"]85[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]17[/TD]
[TD="class: xl69"]Employers Assurance Company[/TD]
[TD="class: xl71, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="class: xl68, align: right"]4095[/TD]
[TD="class: xl69"]C MONDAVI & FAMILY[/TD]
[TD="class: xl69"]P. O. BOX 191 2800 NORTH MAIN STREET[/TD]
[TD="class: xl69"]ST. HELENA[/TD]
[TD="class: xl69, align: right"]94574[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]Napa County[/TD]
[TD="class: xl69, align: right"]2142[/TD]
[TD="class: xl69"]WINERIES[/TD]
[TD="class: xl69, align: right"]133[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]17[/TD]
[TD="class: xl69"]Travelers Property Casualty Company of America[/TD]
[TD="class: xl71, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="class: xl72, align: right"]7028[/TD]
[TD="class: xl73"](DBA) BAY AREA BAGELS[/TD]
[TD="class: xl73"]260 LORTON AVE[/TD]
[TD="class: xl73"]BURLINGAME[/TD]
[TD="class: xl73, align: right"]94010[/TD]
[TD="class: xl73"]CA[/TD]
[TD="class: xl73"]San Mateo County[/TD]
[TD="class: xl73, align: right"]8078[/TD]
[TD="class: xl73"]SANDWICH SHOPS[/TD]
[TD="class: xl73, align: right"]77[/TD]
[TD="class: xl74, align: right"]2/16/18[/TD]
[TD="class: xl73, align: right"]18[/TD]
[TD="class: xl73"]Mid-Century Insurance Company[/TD]
[TD="class: xl75, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="class: xl68, align: right"]9770[/TD]
[TD="class: xl69"]GREEN VALLEY LANDSCAPE AND MAINTENANCE INC[/TD]
[TD="class: xl69"]1182 INDUSTRIAL AVE[/TD]
[TD="class: xl69"]ESCONDIDO[/TD]
[TD="class: xl69, align: right"]92029[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]San Diego County[/TD]
[TD="class: xl69, align: right"]42[/TD]
[TD="class: xl69"]LANDSCAPE GARDENING[/TD]
[TD="class: xl69, align: right"]125[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]18[/TD]
[TD="class: xl69"][/TD]
[TD="class: xl76"][/TD]
[/TR]
</tbody>[/TABLE]
My goal is to find the businesses within certain counties (Column G). I want to delete the data that is irrelevant.
I poked around online and found a walk-through that looked promising. I re-purposed the code (pasted below).
Goal: I want to delete the rows that do not contain multiple specific text values in column G. Here is the code:
I get a "Type mismatch" error and the debugger points to this line "Case Is <> Counties"
FYI...The walk-through outlined different options including "If Not IsError(.Value) Then" and also "Select Case .Value". I got the same error on both approaches.
Any suggestions?
Questions: Does it matter if my data is set as a table versus an array?
Thanks a bunch.
My Book contains businesses and address info, like this:
<style>table { }tr { }col { }br { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: black; font-size: 12pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; vertical-align: bottom; border: medium none; white-space: nowrap; }.xl65 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl66 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl67 { color: white; font-weight: 700; border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(68, 114, 196) none repeat scroll 0% 0%; }.xl68 { border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl69 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl70 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl71 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl72 { border-color: rgb(142, 169, 219) currentcolor rgb(142, 169, 219) rgb(142, 169, 219); border-style: solid none solid solid; border-width: 0.5pt medium 0.5pt 0.5pt; }.xl73 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; }.xl74 { border-color: rgb(142, 169, 219) currentcolor; border-style: solid none; border-width: 0.5pt medium; }.xl75 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; }.xl76 { border-color: rgb(142, 169, 219) rgb(142, 169, 219) rgb(142, 169, 219) currentcolor; border-style: solid solid solid none; border-width: 0.5pt 0.5pt 0.5pt medium; background: rgb(217, 225, 242) none repeat scroll 0% 0%; }.xl77 { text-align: center; }</style> [TABLE="width: 923"]
<tbody>[TR]
[TD="width: 17"][/TD]
[TD="class: xl77, width: 87"]A[/TD]
[TD="class: xl77, width: 87"]B[/TD]
[TD="class: xl77, width: 87"]C[/TD]
[TD="class: xl77, width: 87"]D[/TD]
[TD="class: xl77, width: 87"]E[/TD]
[TD="class: xl77, width: 87"]F[/TD]
[TD="class: xl77, width: 87"]G[/TD]
[TD="class: xl77, width: 87"]H[/TD]
[TD="class: xl77, width: 87"]I[/TD]
[TD="class: xl77, width: 87"]J[/TD]
[TD="class: xl77, width: 87"]K[/TD]
[TD="class: xl77, width: 87"]L[/TD]
[TD="class: xl77, width: 87"]M[/TD]
[TD="class: xl77, width: 87"]N[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="class: xl65"]BureauNumber[/TD]
[TD="class: xl66"]Primary Name[/TD]
[TD="class: xl66"]Street Address[/TD]
[TD="class: xl66"]City[/TD]
[TD="class: xl66"]Zip Code[/TD]
[TD="class: xl66"]State[/TD]
[TD="class: xl66"]County[/TD]
[TD="class: xl66"]Governing Class[/TD]
[TD="class: xl66"]Description[/TD]
[TD="class: xl66"]ExMod[/TD]
[TD="class: xl66"]Updated On[/TD]
[TD="class: xl66"]ExModYear[/TD]
[TD="class: xl66"]InsurerName[/TD]
[TD="class: xl67"]CoverageDate[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="class: xl68, align: right"]3484[/TD]
[TD="class: xl69"]M P A SALES, INC.[/TD]
[TD="class: xl69"]13700 VAN NESS AVENUE[/TD]
[TD="class: xl69"]GARDENA[/TD]
[TD="class: xl69, align: right"]90249[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]Los Angeles County[/TD]
[TD="class: xl69, align: right"]8018[/TD]
[TD="class: xl69"]STORES-WHOLESALE[/TD]
[TD="class: xl69, align: right"]85[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]17[/TD]
[TD="class: xl69"]Employers Assurance Company[/TD]
[TD="class: xl71, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="class: xl68, align: right"]4095[/TD]
[TD="class: xl69"]C MONDAVI & FAMILY[/TD]
[TD="class: xl69"]P. O. BOX 191 2800 NORTH MAIN STREET[/TD]
[TD="class: xl69"]ST. HELENA[/TD]
[TD="class: xl69, align: right"]94574[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]Napa County[/TD]
[TD="class: xl69, align: right"]2142[/TD]
[TD="class: xl69"]WINERIES[/TD]
[TD="class: xl69, align: right"]133[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]17[/TD]
[TD="class: xl69"]Travelers Property Casualty Company of America[/TD]
[TD="class: xl71, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="class: xl72, align: right"]7028[/TD]
[TD="class: xl73"](DBA) BAY AREA BAGELS[/TD]
[TD="class: xl73"]260 LORTON AVE[/TD]
[TD="class: xl73"]BURLINGAME[/TD]
[TD="class: xl73, align: right"]94010[/TD]
[TD="class: xl73"]CA[/TD]
[TD="class: xl73"]San Mateo County[/TD]
[TD="class: xl73, align: right"]8078[/TD]
[TD="class: xl73"]SANDWICH SHOPS[/TD]
[TD="class: xl73, align: right"]77[/TD]
[TD="class: xl74, align: right"]2/16/18[/TD]
[TD="class: xl73, align: right"]18[/TD]
[TD="class: xl73"]Mid-Century Insurance Company[/TD]
[TD="class: xl75, align: center"]##########[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="class: xl68, align: right"]9770[/TD]
[TD="class: xl69"]GREEN VALLEY LANDSCAPE AND MAINTENANCE INC[/TD]
[TD="class: xl69"]1182 INDUSTRIAL AVE[/TD]
[TD="class: xl69"]ESCONDIDO[/TD]
[TD="class: xl69, align: right"]92029[/TD]
[TD="class: xl69"]CA[/TD]
[TD="class: xl69"]San Diego County[/TD]
[TD="class: xl69, align: right"]42[/TD]
[TD="class: xl69"]LANDSCAPE GARDENING[/TD]
[TD="class: xl69, align: right"]125[/TD]
[TD="class: xl70, align: right"]2/16/18[/TD]
[TD="class: xl69, align: right"]18[/TD]
[TD="class: xl69"][/TD]
[TD="class: xl76"][/TD]
[/TR]
</tbody>[/TABLE]
My goal is to find the businesses within certain counties (Column G). I want to delete the data that is irrelevant.
I poked around online and found a walk-through that looked promising. I re-purposed the code (pasted below).
Goal: I want to delete the rows that do not contain multiple specific text values in column G. Here is the code:
Code:
Sub RemoveCounties()
'
' RemoveCounties Macro
'
'
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Counties As Variant
Counties = Array("Los Angeles County", "Orange County", "Riverside County", "San Bernardino County", "San Diego County")
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the G column in this example
With .Cells(Lrow, "G")
Select Case .Value
[B]Case Is <> Counties[/B]: .EntireRow.Delete
End Select
'If Not IsError(.Value) Then
'If .Value <> Counties Then .EntireRow.Delete
'This will delete each row that does not contain one of the counties listed in the variable above
'in Column G, case sensitive.
'End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
I get a "Type mismatch" error and the debugger points to this line "Case Is <> Counties"
FYI...The walk-through outlined different options including "If Not IsError(.Value) Then" and also "Select Case .Value". I got the same error on both approaches.
Any suggestions?
Questions: Does it matter if my data is set as a table versus an array?
Thanks a bunch.