Array numberformat: need to change

HankJ

Board Regular
Joined
Mar 5, 2016
Messages
89
Hi
I'm learning about splitting and joining.
I have a cell, which is a dose response of concentrations in scientific notation.
I have got to the step where my array is filled with each concentration.
I now need to change the format from 1.0E-6 to 0.000001
I've attempted:

HTML:
WrdArray(i) = Format(WrdArray(i), "General")

and I get a Type mismatch error

HTML:
WrdArray(i).NumberFormat = "General"

and I get invalid qualifier...

There must be a way.

Many thanks

Hankj
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
maybe put the 1.0E-6 into a helper cell that is formatted to 6 dec places, then copy and paste that cell back into your original cell ?
 
Upvote 0
maybe put the 1.0E-6 into a helper cell that is formatted to 6 dec places, then copy and paste that cell back into your original cell ?

Hi OldBrewer
Thank you for this.
I was hoping to do this step without copying and pasting into a cell. I am still a novice at this and I have columns of deconstructed dose responses doing just this.

Yours

Hankj
 
Upvote 0
Could we see the code of how WrdArray is declared and how it is filled from the worksheet?
 
Upvote 0
Could we see the code of how WrdArray is declared and how it is filled from the worksheet?

The aim is convert a string from M units to µM and the format to be general instead of Sci

The string in A1 is:
[TABLE="width: 238"]
<colgroup><col width="174"><col width="64"></colgroup><tbody>[TR]
[TD="width: 174"]
[TABLE="width: 200"]
<colgroup><col width="174"></colgroup><tbody>[TR]
[TD="width: 174"]1.0E-4,1.0E-5,1.0E-6,1.0E-7
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="width: 64"][/TD]
[/TR]
</tbody>[/TABLE]

and B1:

[TABLE="width: 64"]
<colgroup><col width="64"></colgroup><tbody>[TR]
[TD="width: 64"]M[/TD]
[/TR]
</tbody>[/TABLE]


and the code... is underdevelopment!!

Code:
Sub Break_String_Test()
    Dim WrdArray() As String
    Dim text_string As String
    text_string = Range("A1").Value
    WrdArray() = Split(text_string, ",")
      For i = LBound(WrdArray) To UBound(WrdArray)
      strg = strg & vbNewLine & "Part No. " & i & " - " & WrdArray(i)
      Debug.Print WrdArray(i)
      Cells(1, 3 + i).Value = WrdArray(i)
      If Cells(0 + 1, 2).Value = "M" Then
      Cells(1, 3 + i).Value = Cells(1, 3 + i).Value * 1000000
      WrdArray(i).NumberFormat = "General"
      Debug.Print WrdArray(i)
      WrdArray(i) = Join(WrdArray(i), ",")
      Debug.Print WrdArray(i)
      Else
      End If
      Next i
    'MsgBox strg
    End Sub

Many thanks Peter

Hankj
 
Upvote 0
[TABLE="width: 832"]
<colgroup><col><col span="10"></colgroup><tbody>[TR]
[TD]1.0E-4,1.0E-5,1.0E-6,1.0E-7[/TD]
[TD="align: right"]27[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0.0001000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0.0000100[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]this macro produced the 4 numbers below[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0.0000010[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0.0000001[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]easy to automate the "print out" part[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Sub Macro4()[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]' Macro4 Macro[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]' Macro recorded 12/10/2017 by bob[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] Dim holder(20)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"] For j = 1 To Cells(1, 2)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 7"] If Mid(Cells(1, 1), j, 1) = "," Then Sum = Sum + 1: holder(Sum) = j - 1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD] Next j[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 5"] Cells(5, 1) = Mid(Cells(1, 1), 1, holder(1))[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 7"] Cells(6, 1) = Mid(Cells(1, 1), holder(1) + 2, holder(2) - holder(1) - 1)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 7"] Cells(7, 1) = Mid(Cells(1, 1), holder(2) + 2, holder(3) - holder(2) - 1)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 5"] Cells(8, 1) = Mid(Cells(1, 1), holder(3) + 2, 15)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD] End Sub[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]A5 down are formatted to 7 decimal places[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Does this macro do what you want...
Code:
Sub Break_String_Test()
  Dim X As Long, Parts() As String
  Parts = Split(Range("A1").Value, ",")
  For X = 0 To UBound(Parts)
    Parts(X) = Format(Parts(X), "#.###############")
  Next
  Range("A1").Value = Join(Parts, ",")
End Sub
 
Upvote 0
Does this macro do what you want...
Code:
Sub Break_String_Test()
  Dim X As Long, Parts() As String
  Parts = Split(Range("A1").Value, ",")
  For X = 0 To UBound(Parts)
    Parts(X) = Format(Parts(X), "#.###############")
  Next
  Range("A1").Value = Join(Parts, ",")
End Sub

Hi Rick

It really is. I managed to come up with the same code myself 20 minutes ago, the penultimate line is the one really new to me and so was just what I wanted.

You've confirmed I was going in the right direction.

Many thanks for your time and help.

Yours

Hank
 
Upvote 0
I managed to come up with the same code myself 20 minutes ago,
May not be important to you but to match the format stated in post 1, the Format pattern would need to be "0.###############"

If interested, and you have Excel 2016 through Office 365, you could also try this one-liner which should do the job for 2-20 joined items in A1.
Rich (BB code):
Sub ConvertFormat()
  Range("A1").Value = Evaluate("textjoin("","",true,iferror(mid(substitute(A1,"","",rept("" "",200)),{" & Join(Application.Transpose(Evaluate("row(1:20)")), ",") & "}*200-199,200)+0,""""))")
End Sub
 
Upvote 0
May not be important to you but to match the format stated in post 1, the Format pattern would need to be "0.###############"

If interested, and you have Excel 2016 through Office 365, you could also try this one-liner which should do the job for 2-20 joined items in A1.
Rich (BB code):
Sub ConvertFormat()
  Range("A1").Value = Evaluate("textjoin("","",true,iferror(mid(substitute(A1,"","",rept("" "",200)),{" & Join(Application.Transpose(Evaluate("row(1:20)")), ",") & "}*200-199,200)+0,""""))")
End Sub

Hello Peter
Thank you for this. I tried it and got a "#NAME?" in A1.

I hope sometime later to post what I have done and then hopefully get a review.

I find I can spend hours getting something work, which is fine but I am pretty sure that there are better ways to do things.

Yours in code

Hank
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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