0

The below code is copying the data fine, however the copy when then number is copied over is copied as text. Is there any way to copy it over as a number?

    Worksheets(1).Range(destCol1 & LR & destCol2 & LR).cells(3).value = Split(srcRange(5).value)

I've tried recording a macro where I'd highlight the data and click the option "Convert text to number" but it's not recording the VBA for that part.

EDIT 1:

With Worksheets(1).Range(destCol1 & LR & destCol2 & LR)
    .cells(1).value = srcRange(2).text
    .cells(2).value = srcRange(1).value
    .cells(3).value = CDbl(Split(srcRange(5).value)(1))
    .cells(4).value = srcRange(6).value 
End With
Maldred
  • 1,074
  • 4
  • 11
  • 33

2 Answers2

0

Untested:

Sub jdskfhs()
    Worksheets(1).Range(destCol1 & LR & destCol2 & LR).Cells(3).Value = CDbl(Split(srcRange(5).Value))
End Sub

EDIT#1:

Here is what you need:

Sub jdskfhs2()
    Worksheets(1).Range(destCol1 & LR & destCol2 & LR).Cells(3).Value = CDbl(Split(srcRange(5).Value)(1))
End Sub

This new code converts the second element of the Split()-generated array to a number.

Gary's Student
  • 95,722
  • 10
  • 59
  • 99
0

After quite a bit of digging, I found another answer on these forums here

I would ideally like to have it all done it one line to reduce processing power as these pages can get quite large; unfortunately this was the best solution I could get.

EDIT:

Using the below code that I modified a bit, but it does work

Private Function TextToNumber(rng As Range)

    LR = ActiveSheet.Range("C" & Rows.Count).End(xlUp).row

    For R = LR To 3 Step -1
        With rng.cells(R, 1)
            .NumberFormat = "General"
            .value = .value
        End With
    Next R

End Function
Maldred
  • 1,074
  • 4
  • 11
  • 33