In actual application scenarios, the address entered by the customer contains carriage return and line breaks, resulting in an error in format conversion. Therefore, you need to clear the line. There are two methods:
1. Replace. This method can only clear one carriage return line break.
'Check whether there is a line break in the address
ADDR = cells (row1, 12)
If instr (1, ADDR, CHR (10), vbbinarycompare)> 0 then
Msgbox ADDR
ADDR = Replace (ADDR, CHR (10), "", vbbinarycompare)
ADDR = Replace (ADDR, CHR (13), "", vbbinarycompare)
Msgbox ADDR
Cells (row1, 12) = ADDR
End if
2. Use the system function to clear all non-printable characters.
'Check whether there is a line break in the address
ADDR = cells (row1, 12)
If instr (1, ADDR, CHR (10), vbbinarycompare)> 0 then
Msgbox ADDR
ADDR = application. worksheetfunction. Clean (ADDR)
Msgbox ADDR
Cells (row1, 12) = ADDR
End if
Want to know moreProgramming Language tutorial setYou can log on to e liangshi Yiyou.
Clear line breaks in strings