+ Reply to Thread
Results 1 to 10 of 10

Can't figure out why the count is messed up?

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Can't figure out why the count is messed up?

    So I wanted to format the data in the attached file. Currently it's all in Col A. I wanted to put it into a new column depending on when the text is bold. Well, almost there but except my count is not working as it should. Can anyone explain to me why? Basically, each new Column should have the text in bold at the first row. I included a counter for j and k to see what was happening. I used "Esc" to get an idea of the scenario and then exit, but in my mind this code should work!

    Please Login or Register  to view this content.
    Any help would be appreciated. Thanks!!!
    Attached Files Attached Files
    Last edited by arlu1201; 05-16-2012 at 02:17 PM. Reason: Code tags not quote tags.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't figure out why the count is messed up?

    It would be helpful to see what the resulting data should look like. I have begun recoding the macro but don't know if I am getting the results you are after. Can you update your files and upload them again.

    Thanks
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can't figure out why the count is messed up?

    it looks like you only ever test A1 to see if it's bold.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Can't figure out why the count is messed up?

    Hey abousetta, I uploaded what the first two columns should look like in Fixture Data Updated, it would be a lot of work doing it for all of them! Hope that gives you the idea...

    Hey JosephP, The macro is testing all the rows in column A. The count i is separate from j and k. "i" basically tests the data for validity and j and k go about formatting it. If you run the macro you would notice it is kinda working but excel is not doing the count of j and k as would be ideal. My ideal format for the 1st two columns is in Fixture Data Updated - I would like that format for all the columns.

    Anyways, thanks both of you for looking into the problem

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can't figure out why the count is messed up?

    no it ain't. you test Selection.Font.Bold but you never select any cell except A1 far as I can see

  6. #6
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Can't figure out why the count is messed up?

    Hey JosephP, excellent. You are right. I just added
    Range("A" & i).Activate
    before
    ActiveCell.Select
    and it works great now. I was confused, because earlier it seemed to be working, but I step late. Nevertheless, thanks a lot. Really appreciate the help. The coding now is:

    Sub LRow()

    Dim LastRow As Long

    'Search for any entry, by searching backwards by Rows.
    LastRow = Range("A1:A65536").Find(What:="Preview Live Report", After:=[A1], _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious).Row

    Range("A1:A" & LastRow).Select

    Dim i As Integer

    j = 0

    For i = 1 To LastRow

    With Range("A" & i)
    If .Cells = "" Then
    Else

    Range("A" & i).Activate
    ActiveCell.Select

    If Selection.Font.Bold = True Then
    Range("A" & i).Copy
    j = j + 1
    Range("A1").Activate
    ActiveCell.Offset(0, j).PasteSpecial
    k = 0

    Else

    Range("A" & i).Copy
    Range("A1").Activate
    k = k + 1
    ActiveCell.Offset(k, j).PasteSpecial


    End If

    End If

    End With


    Next i


    End Sub

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can't figure out why the count is messed up?

    you don't actually have to select anything
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Can't figure out why the count is messed up?

    Well, I wanted to get rid of the blank spaces and start at row 1 each time there was font in bold. That was why I included the
    Range("A1").Activate

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Can't figure out why the count is messed up?

    see my code above, there's no need to select a cell and then refer to activecell or selection.

  10. #10
    Registered User
    Join Date
    10-18-2011
    Location
    Where do we go now?
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Can't figure out why the count is messed up?

    I did try it out, it seems to be shifting a column each time it hits text with bold font (which is what I wanted). But the blank spaces are still there and the text is getting offset by k (meaning if k=1, j=1 and the text is in Cell "A3" then it is going to Cell "B4", so there is now 3 blank cells below the text in Cell "B1"). Additionally the next text with bold font is starting at Cell "C64"

    My reason for going back to Cell "A1" as the active cell was so that I could have no blank spaces and each time the program hits bold text, it would start the next column at row 1 i.e. the 1st Bold text will start at Cell "B1", then the next bold text will start at Cell "C1" and so on.

    Hope that clears up, what I was intending to do. I am open to the idea of a more simple and elegant solution, if there is one. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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