hi all,
i have the data sample as per the attachment, what i need is a way to convert the data in column a, to the format in column b. assume excel2010
Tia
dubdub
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » data reformat
Dub,
Try This:
Public Sub test() col = 1 [COLOR=”#008000″]’CHANGE THE 1 TO THE COLUMN OF DATA[/COLOR] LastRow = ActiveSheet.Cells(Rows.Count, col).End(xlUp).Row Data = “(” For i = 2 To LastRow – 1 Data = Data & “‘” & Cells(i, col).Value & “‘,” Next i Data = Data & “‘” & Cells(i, col).Value & “‘)” Cells(2, 2).Value = Data [COLOR=”#008000″]’CHANGE THE COORDINATES TO THE CELL YOU WANT TO POPULATE[/COLOR] End Sub
(‘wert-12′,’rtyu-1′,’rtyu-1111′,’dfrt-123’)
The code will automatically find the last row of data in column 1. It will take all the values in column A and build a single string with the values inside single quotes, separated by commas, and wrapped in parentheses as you displayed in your sample. The code will accommodate added values in column A by rerunning the code. Place it in a standard module.
HTH,
Ted
If you are looking for a formula to enter into a cell, here is some code that needs to be run only once that will build Steve’s formula into the cell B2 and append it up to the last row. The entered formula will function as if you directly entered it into the formula bar yourself, however saving the time for 300 references. I believe there is a limit to the size of a formula that the formula bar will accept. This may have been a limitation for older versions but, correct me if I am wrong, 256 characters comes to mind.
Public Sub WriteFormula() col = 1 [COLOR=”#008000″]’CHANGE THE 1 TO THE COLUMN OF DATA[/COLOR] LastRow = ActiveSheet.Cells(Rows.Count, col).End(xlUp).Row calc = “=” & Chr(34) & “(‘” & Chr(34) & “&” For i = 2 To LastRow – 1 calc = calc & “A” & i & “&” & Chr(34) & “‘,'” & Chr(34) & “&” Next i calc = calc & “A” & i & “&” & Chr(34) & “‘)” & Chr(34) Cells(2, 2).Formula = calc [COLOR=”#008000″]’CHANGE THE COORDINATES TO THE CELL YOU WANT TO POPULATE[/COLOR] End Sub
With 300 rows, you will easily exceed the formula size limit if one does exist, in which case, you can break the column into segments or run the code from my previous post.
HTH,
Maud
That space is because of the wrap-around in the reply.
The following should handle the apostrophes.
=IF(0=MOD(ROW()-2,4),”(‘”&INDIRECT(“A”&ROW())&”‘,'”&INDIRECT(“A”&1+ROW())&”‘,'”&INDIRECT(“A”&2+ROW())&”‘,'”&INDIRECT(“A”&3+ ROW())&”‘)”,””)
If dubdub wanted a rolling group of 4 as long as there was a group of 4, this ought to do it:
=IF(“”INDIRECT(“A”&(ROW()+3)),”(‘”&INDIRECT(“A”&ROW())&”‘,'”&INDIRECT(“A”&1+ROW())&”‘,'”&INDIRECT(“A”&2+ROW())&”‘,'”&INDIRECT(“A”&3+ROW())&”‘)”,””)
Hmm. Went to Upper Moreland H.S. Went to Bloomsburg under grad and Bucknell grad school. Small world that you lived there, too. Used to work summers at Willow Grove Park — that should date me big time!! Just in case you didn’t know…went from WGP to the largest bowling alley on 1 floor to the mall. Trivia history.
Rode many times on the White alps, the Thunderbolt, and the moon ride. Did you prefer the red side or the blue side in the bowling alley? Midnight bowling with the blue pin. They never had tournaments there because it was built over the lake and the lanes were warped. I hung out at Shaw’s Speed shop and Horn and Hardarts’. Remember Murphy’s 5 & 10 before it became Marshall’s. Went to Arch Bishop Wood but knew many from UMHS. Temple U for me. I think we are both antiques.
True!
I think what dubdub wants is to take an entire column and transpose it horizontally into one cell. From his post, I gather that he is not looking to copy the formula down in every cell in column B, he just doesn’t want to to manually enter 300 cell references into one formula. He may be looking for a formula to do this with a range. Dub, apologies if I am mistaking the intent of your post.
Dub,
The first code will do just that. It will take all the cell values from col A, build the string with the puntuation, then place the string in cell B2. My second code will build Steve’s formula, which works well, from all the cell values in col A, place the formula in cell B2, and then the completed formula will build the string.
Kweaver presented an ingenius approach, one that I would not have thought of doing, to build the sample string. His works perfectly also. If they can work a range into the formula, I would use their solution first.
Good luck,
Maud
This has been an interesting and fun problem. Maud’s solution in VB is the best way to accomplish the result you want, dub.
It quickly places all the cells together, properly formatted, in ONE cell. I’ve attached a sample workbook with that solution as well as my two versions, and even a strange third version that ultimately does what you want without VB, but you have to adjust the LAST row and then copy it to the cell you want (the last row has the ultimate solution). I had to create the first cell and then the second, then fill down and fix the last cell. (ugly)
This was fun to think about.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications