VBA Convert Range to into explizit values

2leet4this

New Member
Joined
Jul 28, 2016
Messages
2
Hello,

apparently I can't find the correct search string to solve my problem (I am completly new to VBA).

I got the following spreadsheet and want to convert the ranges to single values without copy/paste hundrets of values.

This is how my spreadsheet looks like:

Value1Range fromRange toValue 2
XX10018972
XX200130782
YY2007892

I need one looking like this:

Value1Range fromRange toValue 2
XX1001002
XX1011012
XX1021022

and so on ...

Can you help me? Thank you for your support :).

Best regards, 2leet4this
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the MrExcel board!

See if this does what you want.

I have assumed ..
- The original data is in columns A:D of the active sheet, starting in cell A1.
- Columns H:K of that same sheet are available to house the results (we can worry about putting them on another sheet later once we are sure the results are what you want).

Test in a copy of your workbook.

Rich (BB code):
Sub Test()
  Dim a As Variant
  Dim i As Long, nr As Long, rws As Long
  
  a = Range("A2", Range("D" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    nr = Range("H" & Rows.Count).End(xlUp).Row + 1
    rws = a(i, 3) - a(i, 2) + 1
    Range("H" & nr).Resize(, 4).Value = Application.Index(a, i, 0)
    Range("J" & nr).Value = a(i, 2)
    Range("H" & nr).Resize(rws).Value = a(i, 1)
    Range("K" & nr).Resize(rws).Value = a(i, 4)
  Next i
  With Range("H2").CurrentRegion
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]+1"
    .Value = .Value
  End With
End Sub
 
Upvote 0
Hello Peter,

works like a charm! Thank you very much :).

No need for further improvement, I can do the rest manually.

Best regards

2leet4this
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

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