Forum Discussion
Mtumushi
Mar 11, 2021Copper Contributor
Transferring specific numbers from a column to a column
How do I move the specific numbers to a column that correspond to the numbers.. Kindly assist For example 1,2,3,5,9 and they are about 500 and I want to copy for example 9 to column 9..
- Mar 11, 2021
Hi Mtumushi
If I understand the requirement correctly, you need below formula:
=IFERROR(INDEX($A:$A,MATCH(COLUMN(),$A:$A,0),1),"")
Please let me know if it works for you. A sample file is also attached for your reference.
Thanks
Tauqeer
HansVogelaar
Mar 11, 2021MVP
I can't do a video conference, if that's what you mean.
Mtumushi
Mar 11, 2021Copper Contributor
May be you can share your email.. Thanks
- HansVogelaarMar 11, 2021MVP
Here is a version of the macro with comments that explain how it works:
Sub MoveNumbers() Dim r As Long ' Row number Dim m As Long ' Last row Dim a() As String ' Array to store the individual parts Dim i As Long ' Index for looping through the array Dim c As Long ' Individual part if numeric ' Turn off screen updating to speed up execution Application.ScreenUpdating = False ' Determine the last row in column 3 (column C) m = Cells(Rows.Count, 3).End(xlUp).Row ' Loop through the rows from row 2 to row m For r = 2 To m ' Split the value of the cell in row r, column c ' with comma plus space as delimiter a = Split(Cells(r, 3).Value, ", ") ' Loop through the array For i = 0 To UBound(a) ' Check whether the i-th part begins with "other" If LCase(a(i)) Like "other*" Then ' If so, write "other" in column 11 (column K) Cells(r, 11) = "other" Else ' Otherwise, it must be a number ' Set c to the numeric value c = a(i) ' Write that number to the appropriate column ' 1 in column 4, 2 in column 5 etc. Cells(r, c + 3).Value = c End If Next i Next r ' Resume screen updating Application.ScreenUpdating = True End Sub - HansVogelaarMar 11, 2021MVP
Thank you for your email. Try this macro:
Sub MoveNumbers() Dim r As Long Dim m As Long Dim a() As String Dim i As Long Dim c As Long Application.ScreenUpdating = False m = Cells(Rows.Count, 3).End(xlUp).Row For r = 2 To m a = Split(Cells(r, 3).Value, ", ") For i = 0 To UBound(a) If LCase(a(i)) Like "other*" Then Cells(r, 11) = "other" Else c = a(i) Cells(r, c + 3).Value = c End If Next i Next r Application.ScreenUpdating = True End Sub - HansVogelaarMar 11, 2021MVP
My email address is hans dot vogelaar at gmail dot com