Replace and Keep VBA code...

szap2

New Member
Joined
Dec 6, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello, I've been trying to look for a post to help my situation but haven't... I'm trying to replace "ERROR" cells with existing data

I'm using a scanner to read multiple tiny barcodes at once. The issue is that the first time it can sometimes miss a couple barcodes to which it reads "ERROR", but can sometimes pick up those barcodes after scanning it a 2nd time (sometimes 3).

I tried using the "IF" statement where if it read the initial part of the barcode, it can assume to replace the cell that reads "ERROR" with the one with the true barcode. I also included "ERROR" as the false value when it was true (when there was indeed no barcode). I used "ISTEXT" since it wouldn't let me use a wildcard *

=IF(ISTEXT(N2),N2,"ERROR")

1670376056929.png



HOWEVER, that 2nd time the scanner can read "ERROR" to a barcode that was scanned successfully the 1st time. Which means that if I drag the "IF" formula all the way through, it will replace the barcode scanned the first time with "ERROR" from the 2nd scanned.

I'm not great at coding, and the internet said to turn to vba. I've tried threads that say to use REPLACE but they specify a word/number/string when I'm trying to replace with data that is already in the sheet AND not turn any barcodes back to "ERROR" from the 2nd scan.

Is there a way to combine Replace and an IF statement so I can do it all in one go? Also, this is my first post ever, so please let me know if none of this makes sense

Thanks!
 

Attachments

  • 1670375924452.png
    1670375924452.png
    24.4 KB · Views: 4

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I am not sure what you need.
Try this.
Maybe you can put the formula below in the cell "L2".
Then copy "L2" to "L3:L16"
Excel Formula:
=IF(M2<>"ERROR",M2,IF(N2<>"ERROR",N2,"ERROR"))
 
Upvote 0
Solution
I am not sure what you need.
Try this.
Maybe you can put the formula below in the cell "L2".
Then copy "L2" to "L3:L16"
Excel Formula:
=IF(M2<>"ERROR",M2,IF(N2<>"ERROR",N2,"ERROR"))
Thank you!!
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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