[Help] Formula to move numbers from one column to multiple rows

colbyclay

New Member
Joined
Jul 30, 2018
Messages
11
Hi all,
I have 1400 Serial number that have a series of codes associated with them. There are too many for a pivot table so I cut/pasted them to a new spreadsheet. I would like to move the codes from under the serial numbers in column A to the rows next to the Serial Number. Can anyone help?

CURRENTDESIRED
1509004415090044693701
693
701
1509004515090045191315567
191
315
567
1509013615090136812
812

<tbody>
</tbody>

Regards!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub MoveSmallNumbersNextToLargeNumbers()
  Dim Ar As Range, SmallNums As Range
  With Range("A1", Cells(Rows.Count, "A").End(xlUp))
    .Cells = Evaluate(Replace("IF(LEN(@)=8,""=""&@,@)", "@", .Address))
    Set SmallNums = .SpecialCells(xlConstants)
    For Each Ar In SmallNums.Areas
      Ar(1).Offset(-1, 1).Resize(, Ar.Count) = Application.Transpose(Ar)
    Next
    SmallNums.ClearContents
    .Value = .Value
  End With
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Give this macro a try...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub MoveSmallNumbersNextToLargeNumbers()
  Dim Ar As Range, SmallNums As Range
  With Range("A1", Cells(Rows.Count, "A").End(xlUp))
    .Cells = Evaluate(Replace("IF(LEN(@)=8,""=""&@,@)", "@", .Address))
    Set SmallNums = .SpecialCells(xlConstants)
    For Each Ar In SmallNums.Areas
      Ar(1).Offset(-1, 1).Resize(, Ar.Count) = Application.Transpose(Ar)
    Next
    SmallNums.ClearContents
    .Value = .Value
  End With
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Hi Rick,
I am gettting an OBJECT REQUIRED error on the first line. ("Sub MoveSmallNumbersNextToLargeNumbers()")
 
Upvote 0
Hi Rick,
I am gettting an OBJECT REQUIRED error on the first line. ("Sub MoveSmallNumbersNextToLargeNumbers()")
:confused: I am not sure how that is possible. Where did you put the code and exactly how did you execute it?
 
Upvote 0
:confused: I am not sure how that is possible. Where did you put the code and exactly how did you execute it?

Hi Rick,
With the sheet I am working off of active, I went to Developer -> Visual Basic

I then opened the VBA project for active page and cut/past the macro.

Then I hit
Run -> Continue
and recieved a Run-time error '424': Object required
 
Upvote 0
Hi Rick,
With the sheet I am working off of active, I went to Developer -> Visual Basic

I then opened the VBA project for active page and cut/past the macro.
That is not where macros should be installed; rather, they should be put in a General Module. Once in the VB editor, click the "Insert" item on the menu bar and then click the item labeled "Module" (do not select the one labeled "Class Module"... that is for something completely different)... copy/paste my code into that and then run it.
 
Upvote 0
That is not where macros should be installed; rather, they should be put in a General Module. Once in the VB editor, click the "Insert" item on the menu bar and then click the item labeled "Module" (do not select the one labeled "Class Module"... that is for something completely different)... copy/paste my code into that and then run it.

Good Morning Rick,
I am now getting a 1004 error. Running the debug, it is highlighting the following line.

Ar(1).Offset(-1, 1).Resize(, Ar.Count) = Application.Transpose(Ar)


Any idea why this would occur?

Thanks
Colby
 
Upvote 0
Good Morning Rick,
I am now getting a 1004 error. Running the debug, it is highlighting the following line.

Ar(1).Offset(-1, 1).Resize(, Ar.Count) = Application.Transpose(Ar)

Any idea why this would occur?
Some questions...

1) What cells are your numbers in?

2) What are in those cells numeric constants or formulas returning numbers?

3) Are there any blank cells within the data?

4) Are your long numbers always eight digits long?

5) Are you running the macro when the sheet with your numbers is active?

6) Are you using a PC or a Mac?
 
Last edited:
Upvote 0
1) What cells are your numbers in? A

2) What are in those cells numeric constants or formulas returning numbers? Numeric Constants

3) Are there any blank cells within the data? No

4) Are your long numbers always eight digits long? No, they range from 7-10 digits long. To take that into account, I changed the "IF(LEN(@)=8" to "IF(LEN(@)>7" but I still get the Ar(1) line 1004 Application defined or object defined error.
5) Are you running the macro when the sheet with your numbers is active? Yes

6) Are you using a PC or a Mac?, PC, Excel 365
 
Upvote 0
What character do you use to separate arguments in a formula... a comma (,) or a semi-colon (;)?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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