How to ferase value in column "Aantal" if "Locatie" is not "A00"

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I got a table with values that are refreshed from a SQL database. I get lines with itemcode, description etc where the stock is in column "J" (Voorraad) on every location (Locatie). What I would like to accomplish is that I won't see the value in column "Aantal" if the "Locatie" in column "I' is not "A00".
This has to be done every time I refresh the table, can this be done?

Thank you for you time and efforts.

Romano

ArtikelcodeOmschrijvingKostprijsVrrdrekOntvgstdatumAantalMagazijnStd_locatieLocatieVoorraad
100000Vito Glaserfix 111 6x2 mm wit - 10x25 m1390111/07/2023961P02B A00121
100001Vito Glaserfix 111 6x2 mm zwart - 10x25 m2390118/04/2023961P04B P04B 106
100002Vito Glaserfix 111 6x3 mm wit - 10x25 m3390111/07/2023961P02B P02B 63
100003Vito Glaserfix 111 6x3 mm zwart - 10x25 m4390125/04/2023961P04B P04B 40
100004Vito Glaserfix 111 6x4 mm wit - 10x25 m5390106/09/2023961P02B P02B 97
100004Vito Glaserfix 111 6x4 mm wit - 10x25 m6390106/09/2023961P02B P02C 60
100005Vito Glaserfix 111 6x4 mm zwart - 10x25 m7390131/03/2021961A00 P04B 53
100006Vito Glaserfix 111 9x2 mm wit - 10x25 m8390118/07/2023601P01B P01B 20
100007Vito Glaserfix 111 9x2 mm zwart - 10x25 m9390116/08/2023601P03B P03B 118
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You could add an additional column, that has a formula something like:
Excel Formula:
=IF(I2="A00",J2,"")
or
Excel Formula:
=IF(I2="A00",J2,0)
depending on whether you want to show 0 or nothing at all when the value in column I is not "A00".

Then you could hide the current column J.
You might also be able to add this calculation right on the SQL side, so it comes over the way you want.

Or are you looking for some VBA code to run against this that actually removes the values from column J?
 
Upvote 0
You could add an additional column, that has a formula something like:
Excel Formula:
=IF(I2="A00",J2,"")
or
Excel Formula:
=IF(I2="A00",J2,0)
depending on whether you want to show 0 or nothing at all when the value in column I is not "A00".

Then you could hide the current column J.
You might also be able to add this calculation right on the SQL side, so it comes over the way you want.

Or are you looking for some VBA code to run against this that actually removes the values from column J?
Thank you for reply,
I think it would be cleaner to use VBA here, but if that answer won't come then I would indeed consider your solution.
 
Upvote 0
If looking for VBA code, maybe something like this:
VBA Code:
Sub MyRemoveValues()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column J
    lr = Cells(Rows.Count, "J").End(xlUp).Row
    
'   Loop through all rows starting on row 2
    For r = 2 To lr
'       Check value in column I
        If Cells(r, "I") <> "A00" Then Cells(r, "J").ClearContents
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
If looking for VBA code, maybe something like this:
VBA Code:
Sub MyRemoveValues()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row with data in column J
    lr = Cells(Rows.Count, "J").End(xlUp).Row
   
'   Loop through all rows starting on row 2
    For r = 2 To lr
'       Check value in column I
        If Cells(r, "I") <> "A00" Then Cells(r, "J").ClearContents
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
I tried it but for some reason it erases all the values in column "J". Any idea why this may happen?
 
Upvote 0
I tried it but for some reason it erases all the values in column "J". Any idea why this may happen?
Usually that means that your values in column I are not really "A00".
Perhaps you have an extra space or other character in there.

If you find one of the rows that contain "A00" in column I, what happens if you enter this formula in some blank cell (let's sy "A00" is in cell I2):
Excel Formula:
=LEN(I2)
If that formula returns anything greater than 3, you have other characters in that cell.
 
Upvote 0
So, it sounds like you have a LOT of extra spaces in there!

Try modifying the code like this, to only check the first 3 characters (I am assuming the extra characters are at the end, and not the beginning):
VBA Code:
Sub MyRemoveValues()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column J
    lr = Cells(Rows.Count, "J").End(xlUp).Row
    
'   Loop through all rows starting on row 2
    For r = 2 To lr
'       Check first 3 characters in column I
        If Left(Cells(r, "I"),3) <> "A00" Then Cells(r, "J").ClearContents
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
So, it sounds like you have a LOT of extra spaces in there!

Try modifying the code like this, to only check the first 3 characters (I am assuming the extra characters are at the end, and not the beginning):
VBA Code:
Sub MyRemoveValues()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row with data in column J
    lr = Cells(Rows.Count, "J").End(xlUp).Row
   
'   Loop through all rows starting on row 2
    For r = 2 To lr
'       Check first 3 characters in column I
        If Left(Cells(r, "I"),3) <> "A00" Then Cells(r, "J").ClearContents
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Good evening,
It works, thank you help. You have made my day.

Romano
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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