+ Reply to Thread
Results 1 to 22 of 22

Grouped Data Blocks editted to Columns of Data based off left cell value?

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Grouped Data Blocks editted to Columns of Data based off left cell value?

    Hello excelforumers,

    I apologize if this has been asked. I have browsed a few sections and not found what I was looking for. The main problem is this issue is broad and I assume it has several different solutions. This may be better suited in the VBA [EDIT:] so I had it moved here XD [END EDIT]

    Here is what I have, there are data 'blocks' that have 2 columns. There are 6 General rows in each block accounting for 6 attributes. The left column is basically an attribute name. The right column is a value. I want to turn each attribute name into a column header and then take all of the values and align them under the correct attribute name. Each row should then have the data 'block's values. One problem is that the 5th attribute sometimes has several values that are stored in separate cells. The values are still adjacent to the attribute cell, however. The blocks are separated by a blank row which will make it easier to keep the data separate.

    So what I was thinking of doing is writing a script that would copy the value in column B (right column as referenced above) and check to see what the attribute from column A (left column as referenced above) it is associated with then paste it in a new sheet under the attribute header. I would continue this until I reached a blank row, indicating the end of a block, then start a new row in the new sheet. Then continue copying the value from B and placing it according to the attribute in A.

    Any information would help. I was at least hoping to find the VBA code for checking an adjacent cells value, and for pasting values into a cell without replacing the current content for the case where the attribute has multiple values.

    Thanks in advance.
    Last edited by BlazzedTroll; 06-05-2013 at 02:23 PM.

  2. #2
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Just to be clear, I am new to VBA scripting for excel but I have had extensive programming training. I think this pseudocode may help.

    First I'll make a new excel sheet with each of the data headers corresponding to the attributes then,

    datablockcounter = 1
    For i=1;i++;End of File (13657 is the last cell)
    if cell B(i) != null then
    copy cell B(i)
    if cell A(i) = Name then
    paste cell B(i) to newsheet in cell Name(datablockcounter)
    else if cell A(i) = Type then
    past cell B(i) to newsheet in cell Type(datablockcounter)
    else if ... //do this for each attribute
    end if
    else datablockcounter ++
    end for

    the paste command I would use would need to be one such that if there is already something in that cell it simply adds it rather than pastes over it.
    I guess I don't need to check an adjacent cell as I originally thought because the attribute is valued into each of the cells via merged cell.

    If someone could convert my pseudocode into VBA, you would be my most favorite compiler evar! XD

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Do you have a sample file that you can upload? It can contain dummy data as long as the format matches the original. Its also better to show us how you want the output to be displayed.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Yes of course... the only reason I would provide dummy data is to keep from looking to nerdy. But because I don't care if I look nerdy I just took a small sample of the data. Sheet1 is what my data currently looks like. Sheet2 is how I was hoping to format it.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Because I understand this site isn't a "do this for me" but a place to get assistance I thought I would point out I am working on this also. I am starting a VBA script and I will update it as I go. I don't doubt that I will eventually figure this one out by myself if no one manages to figure this out. I'm new to VBA (in fact this will be my first macro programmed in VBA). I have extensive programming training in C++, Java, Basic and some Python. I can read pretty much any code and figure out what it is the program is doing. So I have been roaming the forum and looking at answers to completely unrelated questions in an attempt to find out the syntax of VBA. So far I know that I will need to start with
    Please Login or Register  to view this content.
    So that's what I got so far. It's not much but... not having worked in VBA before I get stuck on what I think should be the syntax and I end up forgetting what I was trying to do in the first place.

    A little edit to the pseudocode above:

    I have decided not to cram data into the same cell when it multiple rows are adjacent to the same attribute. Instead I will keep them in separate cells.
    So when I reach the if statement that would be

    If Cells(A , i) = Rules Text then

    I will need a while statement that says
    j = 1
    while Cells (A , i+j) = Rules Text then
    //add one to the datablockcounter because there will be a second cell down and I don't want to start the next data row on top of it
    datablockcounter ++
    //then add this block to the range that will be copied
    j ++
    end

    This way it will copy all the cells that are associated with the Rules Text attribute in that data block will be copied together and the row counter will be incremented for each one to make sure no data is inadvertently overwritten.

  6. #6
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    MOVE THREAD REQUEST

    I just noticed I originally posted this under General because I wasn't sure what path I was going to take to solve this. Now that I know I am going to be scripting something in VBA. Will one of the mods move this thread to VBA Scripting so that I may get the proper assistance?

    Thanks!

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Thread moved. Thanks for asking it to be moved rather than creating a duplicate thread.

  8. #8
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Not a problem. I've been a mod on a few forums over the years. x-posts can get quite overwhelming. I'm just trying to keep things organized so that people can find my thread and I will get the answers I am looking for.

  9. #9
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    As promised I am back. I think I may actually get this done more quickly than I originally thought. I just hope when I am done it does what I think it will XD
    Hopefully this will help someone since I went through the effort of posting all of this. I'll be sure to paste the final working (hopefully) marco here.

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    I was going to work on a solution for you. Is your code above working? Or is it giving an error?

  11. #11
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    It's not done yet. But I did a test run. First of all I mispelled Worksheets, Worsheets. After fixing that. I get an error. Expected Sub - it highlights Ln 63
    Please Login or Register  to view this content.
    This line was supposed to be dataBlockCounter ++ but it didn't like that. So I made it dataBlockCounter + 1 and it autocorrected it to dataBlockCounter 1

    I was going to write the while loop for Rules Text, then get back to it.

    Any help is much appreciated.

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Will you be fine if i re-work the whole code? I find it easy to get it working that way. Also, it could be a learning for you.

    For e.g. you do not need all the Select and Activate statements and you can make the code run faster without them.

  13. #13
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Re-working is completely fine. I have little experience in this language so most of this is probably nonsense. If it will rearrange the data, that's all that matters.

    And yes, I saw something about the copy and paste functions in VBA and they had turned my 3 lines into 1 basically but once I started writing I couldn't find it again. I figured long code was better than no code or just pseudocode. I'm not worried about size or speed of the code though. I understand a code-monkeys natural need to make it concise though and definitely don't mind that.

    EDIT: Didn't want to post again,
    There is a logical error in my code above in case you are just editing my code. Name is the only attribute not followed by a colon. I had to change "Type" to "Type:", "Cost" to "Cost:" ... ect.
    Last edited by BlazzedTroll; 06-05-2013 at 03:21 PM.

  14. #14
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    So I am stuck... This is my code so far that should be working as far as I am concerned (I haven't been able to really check for logical errors because I can't get it to run):
    Please Login or Register  to view this content.
    When I try to run the code I get an Error box that reads:

    Run-time error '1004':

    Application-defined or object-defined error
    As far as I can tell it isn't highlighting any certain area and I can't figure out what it would be referring too. Most of this code was hacked together from other sources as I said above. Anyone know what it may be referring too? Also, I still can't find that post about copy and paste functions. I know I don't need to select copy select paste, what is the shorter code for this?

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Sorry, i have not been able to work on this. Will try something today for sure.

  16. #16
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    No problem, I was glad you weren't looking for me yesterday. I had to split out early. I've taken this as far as I can. Thank you for your help! Happy Friday!

  17. #17
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    This was Solved.

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    BlazzedTroll,

    In future, please refrain from creating duplicate threads. Please check rule 5 of the forum rules.

  19. #19
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Lol... It's not really a "duplicate" thread. That rule is referring to people who post exact copies in multiple threads at the same time hoping to get a super fast answer. I posted this here and after you lied and said you would assist me and then never did. I created a new post with a link to this post, as the rules say on cross-posting. Then when that thread was solved, also solving this thread. I posted a link. Completing the thread.

    You may want to check the rules on common courtesy. One might say it is common courtesy to not say you are working on a solution when you clearly are not. I gave you reputation and I wish I could take it back. If you go posting "I'm working on this" another moderator or someone looking to help may think 'Hey, someone is already helping here. I may be better off helping someone else'. Then when it turns out you were lying, that person gets no assistance and you have essentially killed a thread. Almost immediately after posting a much need revised post, I got the help I needed and my problem was solved. Something you failed to do. And as far as I can tell never planned on doing.

  20. #20
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Cross posting is when you post in different forums on the web, not within the same forum. Duplicate posting is when you post in multiple forums in the same website, irrespective of whether the content is exactly the same or not, as long as the question revolves around the same aspect, its termed as duplicate.

    One thing you should remember is that this is a free forum. Each person assisting here will also have other commitments and may not be always available to answer the questions. People take the time to help others and its possible that any person assisting you would be caught up in other urgent commitments. That doesnt imply that they are lying. They could be really held up with stuff and being administrator or moderator of a forum, does create a lot of work.

    I have seen several threads where i have been working on a solution and others have come forward with a solution while i have also been working on it. And this is perfectly fine. So even if i put in the words, "i am working on it", others do come forward if they can put forth an answer to the question.

    And for volunteering to help you out, i dont think i deserve the rude reply i received from you.

  21. #21
    Registered User
    Join Date
    06-04-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    After I told you I was a Mod on several forums in the past, don't you think I know the difference between a x-post and a duplicate thread. I was pointing out that I wasn't breaking any forum rules. This was not a duplicate thread. This thread started out with me having no idea how to program something in VBA. Then as I was waiting on you to reply and search by myself, I came across the information I needed. I posted a RELATED thread. With a link to the background information. That thread is not asking the same thing I am asking in this thread. That thread is asking about the Error 1004 as the title of that thread would suggest. I don't think I deserve the "learn how to post" reply I got from you. But I got one none the less. So, now that you have got your chance to rage a little bit about nothing related to this thread. Would you please let this thread die. I have already marked it as solved. There is no need for this useless bickering you are inciting now.

  22. #22
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Grouped Data Blocks editted to Columns of Data based off left cell value?

    Ok, my mistake that i considered it as duplicate. It could be a "related" thread. I have explained to you the difference between cross posting and duplicate posting with regards to this forum.

    Anyways, let bygones be bygones and i will let this thread die.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1