vba - Remove extra spaces from cells in column -
i wrote following code inventory scanning bar-codes reason when scan bar-code adding spaces in cells , result not showing expected.
how remove spaces cells in column?
option explicit private sub workbook_sheetchange(byval sh object, byval target range) if target.cells.count > 1 or isempty(target) or target.column <> 1 exit sub if not sheetexists("warehouseinventory") exit sub dim result variant set result = sheets("warehouseinventory").cells.range("e:e").find(target) if result nothing target.worksheet.cells(target.row, 2) = "data maybe bin #?" else target.worksheet.cells(target.row, 2) = result.worksheet.cells(result.row, 4) target.worksheet.cells(target.row, 3) = result.worksheet.cells(result.row, 5) target.worksheet.cells(target.row, 4) = result.worksheet.cells(result.row, 6) target.worksheet.cells(target.row, 5) = result.worksheet.cells(result.row, 7) end if end sub public function sheetexists(sheetname string) boolean dim ws worksheet sheetexists = false each ws in thisworkbook.worksheets if ws.name = sheetname sheetexists = true next ws end function
barcode scan on column a
when scan barcode add spaces in cells , result not showing expected.
the idea not trim cells later trim bar code entry @ time of scanning. want? put in code area of relevant sheet. assuming bar code scanned in col b e.
private sub worksheet_change(byval target range) on error goto whoa if target.cells.count > 1 exit sub application.enableevents = false '~~> assuming bar code scanned in b e '~~> if 1 column b change '~~> code below '~~> if not intersect(target, columns("b:b")) nothing if not intersect(target, columns("b:e")) nothing target.value = trim(target.value) end if letscontinue: application.enableevents = true exit sub whoa: msgbox err.description resume letscontinue end sub
Comments
Post a Comment