vba at each change

panyagak

Active Member
Joined
Feb 24, 2017
Messages
299
Hi all.

Microsoft 2010 in use

This is simplified data (Range to last cell on column A) arranged vertically for ease of presentation.

i would like to Transform the arrangement using vba possibly using "At each change in DIM" convert to this horizontally To This:

DIM 1 2 3 4 5 6
DIM 7 8 9 10 11 12
etc up to last cell.

My data as simplified:
DIM
1
2
3
4
5
6
DIM
7
8
9
10
11
12
DIM
13
14
15
16
17
18
DIM
.
.
.

Thanks as I prepare to sleep

Regards
Patrick
 
OK, it's difficult to see where your data actually begins in your original post. To demonstrate, starting with the following assumed layout of your data:
Book1
A
1DIM
21
32
43
54
65
76
8DIM
97
108
119
1210
1311
1412
15DIM
1613
1714
1815
1916
2017
2118
22DIM
Sheet1


The first option returned this:
Book1
A
1DIM 1 2 3 4 5 6
2DIM 7 8 9 10 11 12
3DIM 13 14 15 16 17 18
4
Sheet1


The second option returned this:
Book1
ABCDEFG
1DIM123456
2DIM789101112
3DIM131415161718
4DIM
5
Sheet1


Could you provide a copy of your actual worksheet using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform?
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Y
OK, it's difficult to see where your data actually begins in your original post. To demonstrate, starting with the following assumed layout of your data:
Book1
A
1DIM
21
32
43
54
65
76
8DIM
97
108
119
1210
1311
1412
15DIM
1613
1714
1815
1916
2017
2118
22DIM
Sheet1


The first option returned this:
Book1
A
1DIM 1 2 3 4 5 6
2DIM 7 8 9 10 11 12
3DIM 13 14 15 16 17 18
4
Sheet1


The second option returned this:
Book1
ABCDEFG
1DIM123456
2DIM789101112
3DIM131415161718
4DIM
5
Sheet1


Could you provide a copy of your actual worksheet using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform

OK, it's difficult to see where your data actually begins in your original post. To demonstrate, starting with the following assumed layout of your data:
Book1
A
1DIM
21
32
43
54
65
76
8DIM
97
108
119
1210
1311
1412
15DIM
1613
1714
1815
1916
2017
2118
22DIM
Sheet1


The first option returned this:
Book1
A
1DIM 1 2 3 4 5 6
2DIM 7 8 9 10 11 12
3DIM 13 14 15 16 17 18
4
Sheet1


The second option returned this:
Book1
ABCDEFG
1DIM123456
2DIM789101112
3DIM131415161718
4DIM
5
Sheet1


Could you provide a copy of your actual worksheet using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform?
You got it CORRECTLY!! A1 downwards THOUGH I cant see the Formulas!!!!
 
Upvote 0
thank you so much kevin9999
kevin9999.
Kevin9999.

effect on a bigger Range

suppose there are uneven breaks apart from the fine data I presented before the next DIM, Code 2 seems to return "Run time Error 9" "Subscript out of Range" - on this line "b(j, k) = a(i, 1)" when my current Range is A1:A1902.

one DIM to the next DIM is not uniform as my simple data demonstrated, it varies
 
Upvote 0
Could you please share your actual data via Google Drive, Dropbox or similar file sharing platform? Only need column A.
 
Upvote 0
Here's a couple of updated modules for you to try:
VBA Code:
Sub In_One_Cell_V2()
    Dim a, b, i As Long, j As Long, s As String
    a = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    
    s = "DIM": j = 1
    For i = 2 To UBound(a, 1)
        If a(i, 1) <> "DIM" And a(i, 1) <> "" Then
            s = s & " " & a(i, 1)
            b(j, 1) = s
        ElseIf a(i, 1) = "DIM" Then
            b(j, 1) = s: j = j + 1: s = "DIM"
        End If
    Next i
    Range("A1").Resize(UBound(b, 1), 1).Value = b
    Range("A:A").EntireColumn.AutoFit
End Sub

VBA Code:
Sub In_Multi_Cells_V2()
    Dim a, b, i As Long, j As Long, s As String
    a = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    
    s = "DIM": j = 1
    For i = 2 To UBound(a, 1)
        If a(i, 1) <> "DIM" And a(i, 1) <> "" Then
            s = s & " " & a(i, 1)
            b(j, 1) = s
        ElseIf a(i, 1) = "DIM" Then
            b(j, 1) = s: j = j + 1: s = "DIM"
        End If
    Next i
    Range("A1").Resize(UBound(b, 1), 1).Value = b
    With Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
        Application.DisplayAlerts = False
        .TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Space:=True
        Application.DisplayAlerts = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

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