Fix Code to Append Expanded Numbers Properly

nabusafe

New Member
Joined
Sep 11, 2018
Messages
5
So I'm having an issue with my current code.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub ExpandRanges()

Dim X As Long, CG As Variant, Rng As Range, Cell As Range
Dim Series As String, CommaGroups() As String, DashGroups() As String
Dim j As Long, lastrow As Long

j
= 0
lastrow
= Cells(Rows.Count, "H").End(xlUp).Row

Set Rng = Range(Range("H2"), Range("H" & lastrow))

For Each Cell In Rng

CommaGroups
= Split(Cell, ",")

For Each CG In CommaGroups

DashGroups
= Split(CG, "-")

For X = DashGroups(0) To DashGroups(UBound(DashGroups))
If j = 0 Then j = Split(Cell.Address, "$")(2)

Rows
(j + 1 & ":" & j + 1).Insert Shift:=xlDown
Cells
(j, 9).Value = X

Range
("A" & j + 1 & ":H" & j + 1).Value = Range("A" & j & ":H" & j).Value

j
= j + 1
Next

Next

Next

'Band-aid solution
lastrow
= Cells(Rows.Count, "H").End(xlUp).Row
Range
("A" & lastrow & ":H" & lastrow).ClearContents

End Sub</code>It currently is expanding the number range for only ONE range of numbers in my excel file, any time I try to add another range it will freeze and not respond.

For example, here is my input data for just one row:

Capture7%20(2).PNG


When I run my code, this is my output which is exactly what I want:

Capture8.PNG


But now the issue is, whenever I got to add another row of number ranges like this:

Capture7%20(3).PNG



My excel pane will freeze and tell me it is not responding.
Any ideas on how to format the code to be able to append all the expanded ranges in new rows? Thanks!!




<tbody>
</tbody>

 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You cannot post pictures that are stored on your local hard drive into a forum. Looking at your code, I think the code I posted in my mini-blog article here may do what you want...

http://www.excelfox.com/forum/showt...list-of-pages-and-ranges-(e-g-1-5-9-12-20-18)

The code at that link handles number sequences. If your values could have beginning non-numeric text in front of your numbers, then you would need the code I posted in a different mini-blog article...

http://www.excelfox.com/forum/showt...ons-(e-g-AB5-AB9-becomes-AB5-AB6-AB7-AB8-AB9)
 
Upvote 0
Upvote 0
Yes I did, but I am not sure how to call a macro to a function like that, sorry I am still learning VBA
 
Upvote 0
I would like to build a code that expands the number ranges in the Destination Zip Range column please, so where it creates new rows for the expanded range numbers.

2i9rnmf.png
[/IMG]
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,813
Members
449,469
Latest member
Kingwi11y

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