PDA

View Full Version : [SOLVED] Column number conversion: hex to dec and dec to hex



wahid_kw1
05-25-2009, 12:55 AM
Hello,

I have an Excel column with hexadecimal numbers and I would like to convert all numbers of the column to decimal numbers.
I tried with many macros but I did not success.

Please help me.


Thank you in advance.

Bob Phillips
05-25-2009, 01:35 AM
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow
.Cells(i, TEST_COLUMN).Value = Application.Run("ATPVBAEN.XLA!HEX2DEC", .Cells(i, TEST_COLUMN).Value)
Next i
End With
End Sub

wahid_kw1
05-25-2009, 01:44 AM
Thank you for your help,but I try with this code and it doesn't work.
Could you give an other code or telle me what can I do exactly in Excel because I don't know very well how working with macros.
I tried with this code and it work,but it is to convert decimal to hexadecimal and I look for the conversion hexadecimal to decimal.


Option Explicit
Sub DecToHex()
Dim LastRow As Long, LastCol As Integer, r As Long, c As Integer
LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
c = 1
For r = 1 To LastRow
For c = 1 To LastCol
If IsNumeric(Cells(r, c)) And Len(Cells(r, c)) > 0 Then
Cells(r, c) = Hex(Cells(r, c))
Cells(r, c).NumberFormat = "@"
End If
Next c
Next r
End Sub


Thank you very much.

Bob Phillips
05-25-2009, 01:46 AM
Go to Tools>Addins and check the items Analysis Toolpak and Analysis Toolpak - VBA, then try it.

wahid_kw1
05-25-2009, 01:54 AM
These tools were added,but the problem I select all Excel column and I execute the macro and I have "0" as result.

Do you try it before?
Could you tell me what should I put in "VB editor"?
Do you have an other code?

Thank you

Bob Phillips
05-25-2009, 02:20 AM
Yes, of course I tried it.

You put that code in a standard module and just ran it. What is in your workbook, can you post it?

wahid_kw1
05-25-2009, 02:39 AM
yes,I have done all these steps,but I have the same result.
I work with Excel 2003.

Could you give me an other code to try it?

Thank you very much

Bob Phillips
05-25-2009, 03:42 AM
Can you post your workbook so that I can see what you are doing wrong?

wahid_kw1
05-25-2009, 04:07 AM
In the module of the VB editor,I write:


Option Explicit

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow
.Cells(i, TEST_COLUMN).Value = Application.Run("ATPVBAEN.XLA!HEX2DEC", .Cells(i, TEST_COLUMN).Value)
Next i
End With
End Sub

and after I run it.
What you mean with workbook?
I don't understand.

Bob Phillips
05-25-2009, 07:32 AM
An Excel workbook, with the data, and the code you entered, attach it to your post.

wahid_kw1
05-25-2009, 07:45 AM
Thank you very much.
I have resolve the problem.

mdmackillop
05-26-2009, 12:29 AM
For the benefit of others who read this, what was the solution to your problem?