How to remove specific values from County table?

vbanewbie68

Board Regular
Joined
Oct 16, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi

How can I get VBA to identify and remove specific county's values like London, France, USA out of the County's column?

Please see my screenshot and my VBA codes.

Also would it be possible to add a valid county table into VBA? For example if value is Scotland under County's column and it is not match with the valid county table then it should be blank.

I hope it makes sense?

Thank you in advance.

Best regards

Rej

1638040726892.png



Sub Add_Rows_Data()


'LastRow = Imprt.Cells(1, 1).End(xlDown).Row
'How to check if a column exists in the sheet, will throw an error if it doesn't exist
'Set Imprt = ThisWorkbook.Sheets("Sheet5")
LastRow = Imprt.Cells(1, 1).End(xlDown).Row


For x = 2 To LastRow



County = WorksheetFunction.Match("County", Import.Cells(1, 1).EntireRow, 0)

'Imprt.Cells(x, County).Value = England, London, Scotland France, USA 'County
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How about:

VBA Code:
    Dim Cell    As Range
    Dim Imprt   As Worksheet
'
    Set Imprt = ThisWorkbook.Sheets("Sheet5")
'
    For Each Cell In Imprt.Range("A2:A" & Imprt.Range("A" & Rows.Count).End(xlUp).Row)
        Select Case Cell.Value
            Case "London", "France", "USA", "Scotland"                                      ' <--- Excluded Counties. Adjust as needed
                Cell.Value = vbNullString
         End Select
    Next
 
Upvote 0
Solution
How about:

VBA Code:
    Dim Cell    As Range
    Dim Imprt   As Worksheet
'
    Set Imprt = ThisWorkbook.Sheets("Sheet5")
'
    For Each Cell In Imprt.Range("A2:A" & Imprt.Range("A" & Rows.Count).End(xlUp).Row)
        Select Case Cell.Value
            Case "London", "France", "USA", "Scotland"                                      ' <--- Excluded Counties. Adjust as needed
                Cell.Value = vbNullString
         End Select
    Next

Hiya

Thanks for this and how to convert your codes into this please? See my another screenshot to see if that is helpful for you?

Best regards

V



1638048276849.png
 
Upvote 0
I am so pleased that the outcome of the county using your VBA codes is working where I have converted it into this way. Please see the VBA below. :). Many thanks for your time and kind help on this matter! I am so pleased.

Best regards

V

Select Case Imprt.Cells(x, County).Value
Case "London", "LONDON", "England", "USA", "France", "Scotland", "United Kingdom" ' <--- Excluded Counties. Adjust as needed
Imprt.Cells(x, County).Value = vbNullString

End Select
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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