PDA

View Full Version : Decimal value of characters in cell



DaveK
07-24-2008, 09:53 AM
I think this is probably easy... if you know how to do it! Can someone help with this... it would be much appreciated! THANKS!

I'd like to know how to have a VBA to look at each and every character in a Selection of cells down a column, and do the following:

1) read the contents, cell by cell, character by character within each cell.
2) allow me to do a check of every character, character by character, to see if it matches a specific character I want to find.
3) output each character of the cell into an adjacent offset column to the right of the current cell, as long as the character is not the special character.
4) checking each character, outputting the same character into the adjacent cell... UNLESS it matches.
5) if it matches the special character (which I want to be able to change), REPLACE that character with the "replacement special character".
6) continue character by character in the cell, outputting all non-matched characters exactly into the adjacent column cell.
7) do this down the column for the current Selection.

So, for example :

first second third fourth first second third fourth
one, two, three one5 two5 three
James,, Wilson Jones James55 Wilson Jones

if Column A has as above, then the VBA writes column B to be as above when the special searched for character = comma. And since we have some characters matched, replace that character with the "replacement special character" = 5.

Now here is really where I need more help as well.

Now for another program, I also want to be able to do similar, but in this case, scan down the current Selection column, and output to the offset column the contents character by character... in DECIMAL value of each character, separated by a space between each decimal value outputted.

In other words,

one 111 110 101
Hello<CR> 72 101 108 108 111 13


I hope you can help me.... THANK YOU ALL sooo much.

Dave

Bob Phillips
07-24-2008, 11:01 AM
The first can be done with a simple Find and Replace.

The second



Public Sub ProcessData()
Dim i As Long
Dim j As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow

For j = 1 To Len(.Cells(i, "A").Value)

.Cells(i, "B").Value = .Cells(i, "B").Text & Asc(Mid$(.Cells(i, "A").Value, j, 1)) & Chr(32)
Next j
Next i

End With

End Sub

DaveK
07-24-2008, 01:57 PM
Thanks for much for guiding me on this... your answer is very helpful... although I admit I dont fully understand it (yet).

It KINDA works... it does not put the SPACE in between the ascii written values... for example:

if Column A has
1 2 3
this program writes into Column B
4932503251

The ascii values are correct, but there is no space in between each.

And with the Mid$ function.... what is the $ for?

THANKS SO MUCH!

Dave

PS... on another topic... but saving a message slot... how to mark a message thread as SOLVED? I cant find how to do it. I even read the FAQ.....

mdmackillop
07-24-2008, 02:10 PM
For j = 1 To Len(.Cells(i, "A").Value)
.Cells(i, "B").NumberFormat = "@"
.Cells(i, "B").Value = .Cells(i, "B").Text & Asc(Mid$(.Cells(i, "A").Value, j, 1)) & Chr(32)
Next j



PS... on another topic... but saving a message slot... how to mark a message thread as SOLVED?

Thread Tools dropdown.

DaveK
07-24-2008, 02:54 PM
THANK YOU SO MUCH!

Dave
:clap2:

DaveK
07-24-2008, 03:02 PM
I spoke too soon... I DOES WORK with VISIBLE PRINTABLE characters...
HOWEVER... I have cells which also have NON-PRINTABLE characters embedded in them... (ie nl cr (del) etc... and I need to see and find these too.

Sooo. I dont think the LEN function is catching these... or the the MID function either.

ANY IDEAS?

THANKS
Dave

mdmackillop
07-24-2008, 03:03 PM
Can you post a sample workbook?

DaveK
07-24-2008, 03:17 PM
Ok, I am uploading EXCEL file ASCII_characters.xls

Note contents of the cells in row2,3,5

I believe there are additional unseen characters in there... as FIND does not work etc if you just use the visable characters. These cell values have been pasted from a database... and I think something is coming along with the values.

THANKS for your help
Dave

mdmackillop
07-24-2008, 03:39 PM
I can't see anything. What is giving you the problem?

DaveK
07-24-2008, 04:01 PM
Notice in the FORMULA BAR when you select cell A5, (or A2), there is a little tick on the very left side of the first word.

When using the VLOOKUP function, it often does not work with this kind of data when just trying to match... and I think something else is in there...

Thanks for helping...

Bob Phillips
07-24-2008, 04:25 PM
For j = 1 To Len(.Cells(i, "A").Value)
.Cells(i, "B").NumberFormat = "@"
.Cells(i, "B").Value = .Cells(i, "B").Text & Asc(Mid$(.Cells(i, "A").Value, j, 1)) & Chr(32)
Next j

Be quicker to do the column in one



.Columns(2).NumberFormat = "@"
For j = 1 To Len(.Cells(i, "A").Value)
.Cells(i, "B").Value = .Cells(i, "B").Text & Asc(Mid$(.Cells(i, "A").Value, j, 1)) & Chr(32)
Next j

DaveK
07-25-2008, 10:37 AM
Please, if someone can help... take a look at the little excel file I uploaded (in earlier message in this thread), and look at the contents of cells A2 or A5.

For example, in A5... when you look at it in the excel spreadsheet, it simply looks as if it has the text of Defining Management

Now look at what is shown in the FORMULA BAR above the spreadsheet... it is different, with the little tick showing at the beginning of the text.

Also, now I think there may be a LF character at the end of the text as well. I was hoping this little program could show me in ASCII numerical number ALL the characters in each cell... not just the 'printable' ones.

Still looking for any advice and help on how to do this.

THANK YOU
Dave

Bob Phillips
07-25-2008, 10:45 AM
That is just a single apostrophe. It is often used if entering say 001 so as not to lose the zeroes, or to sop say 01/04 being converted to a date.

DaveK
07-28-2008, 06:43 AM
For example, in A5... when you look at it in the excel spreadsheet, it simply looks as if it has the text of Defining Management

I think there may be a LF character at the end of the text as well. I was hoping this little program could show me in ASCII numerical number ALL the characters in each cell... not just the 'printable' ones.

Still looking for any advice and help on how to do this.


Dear xld or someone, I really think something is in these cells and not just printable viewable characters, and the VBA seems to only see the printable characters... so I am unable to truly find out the contents of these cells. Surely there must be a way.

Try this. Select cell A5, COPY it to clipboard, and go into OUTLOOK, paste into a new message. NOTICE at the end of the text, when you edit it, the cursor is NOT at the end of the word, but it is further to the right... like there is something else there. This would not happen if I simply pasted text.

Any help would be very much appreciated.

Thanks to all.

mdmackillop
07-28-2008, 02:31 PM
Hi Dave
I've removed "Solved" from your thread
While there may be unseen characters, how does this affect what you are trying to achieve?
Regards
MD