I'm copying HTML-based content and pasting it into a spreadsheet. I need to repeat this process for multiple rows in an accounting document. Because the values or length of the copied strings change and the spaces are uneven, I don't think use of the LEFT
, RIGHT
or MID
functions will work.
Though the source content appears tabular in HTML in six adjacent horizontal cells / columns, Excel views it as unicode and pastes it like this in one cell (note that the column spaces are uneven; all contents displayed are in one cell as text):
Revenues 111,234 222,345 333,456 444,567 555,678
Revenues 666,789 777,890 888,901 999,012 1,111,234
It should instead paste like this (with tabs as separators):
Revenues 111,234 222,345 333,456 444,567 555,678
Revenues 666,789 777,890 888,901 999,012 1,111,234
I've tried every paste special format and none worked. I've also tried recording a macro that cuts the five numeric values from the cell and pastes each separately in adjacent columns as desired.
Below is the recorded macro:
Sub Copy_Cell_Part_and_Paste_In_Adjacent_Cells()
'
' Copy_Cell_Part_and_Paste_In_Adjacent_Cells Macro
'
' Keyboard Shortcut: Ctrl+u
'
ActiveCell.FormulaR1C1 = "Revenues "
Range("B1").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "111,234"
Range("C1").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "222,345"
Range("D1").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "333,456"
Range("E1").Select
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = "444,567"
Range("F1").Select
ActiveSheet.Paste
End Sub
Yes, the macro has many problems including use of absolute instead of relative references and it copies the original cell content to the fifth cell to the right.
How do I cut (not copy) the numeric values part of a string in a cell and paste the cut values in adjacent cells? If the question need be more specific: (1) How do I automate cutting only part of any selected cell(s) using relative references? (2) How do I distribute the contents of those cut cells to adjacent cells?
EDIT: Changed to clarify the array should be the selected cells, which may in multiple rows in one column