how to convert column a question to column b (sorry xl2bb is not working )

Kichan

Board Regular
Joined
Feb 21, 2022
Messages
67
Office Version
  1. 2010
Platform
  1. Windows
Untitled.jpg
how to convert column a question to column b (sorry xl2bb is not working )
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Upvote 0
Try:
VBA Code:
Sub ConvertData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, Val As Variant, arr() As Variant, lRow As Long, x As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("A2:A" & lRow).Value
    For i = LBound(v) To UBound(v)
        Val = Split(v(i, 1), " = ")
        x = x + 1
        ReDim Preserve arr(1 To x)
        arr(i) = "{ " & """" & Val(0) & """" & ", answer: " & """" & Val(1) & """" & " },"
    Next i
    Range("A2").Resize(UBound(arr)) = Application.Transpose(arr)
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
not following 100%
What version of Excel - Still 2010 ?
="{ question: "&LEFT(A2,SEARCH("=",A2,1)-1)&""", answer: """&RIGHT(A2,LEN(A2)-SEARCH("=",A2,1))&"""},"

Book1
AB
1
2Question 1 = answer to Question 1{ question: Question 1 ", answer: " answer to Question 1"},
3Question 2 = answer to Question 2{ question: Question 2 ", answer: " answer to Question 2"},
4
Sheet1
Cell Formulas
RangeFormula
B2:B3B2="{ question: "&LEFT(A2,SEARCH("=",A2,1)-1)&""", answer: """&RIGHT(A2,LEN(A2)-SEARCH("=",A2,1))&"""},"
Thank you very much
 
Upvote 0
Try:
VBA Code:
Sub ConvertData()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, Val As Variant, arr() As Variant, lRow As Long, x As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("A2:A" & lRow).Value
    For i = LBound(v) To UBound(v)
        Val = Split(v(i, 1), " = ")
        x = x + 1
        ReDim Preserve arr(1 To x)
        arr(i) = "{ " & """" & Val(0) & """" & ", answer: " & """" & Val(1) & """" & " },"
    Next i
    Range("A2").Resize(UBound(arr)) = Application.Transpose(arr)
    Application.ScreenUpdating = True
End Sub
thank you very much
 
Upvote 0
If vba,
Code:
Sub test()
    Dim a, i&, x
    With Range("a2", Range("a" & Rows.Count).End(xlUp))
        a = .Value
        ReDim Preserve a(1 To UBound(a, 1), 1 To 2)
        For i = 1 To UBound(a, 1)
            If a(i, 1) Like "*=*" Then
                x = Application.Trim(Split(a(i, 1), "="))
                a(i, 1) = Join(Array("{ question: ", x(1), " "" ,answer: ", x(2), """},"), "")
            End If
        Next
        .Columns(2) = a
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,575
Messages
6,160,603
Members
451,657
Latest member
Ang24

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