Consulting

Results 1 to 4 of 4

Thread: Need assistance with merging rows, please.

  1. #1

    Need assistance with merging rows, please.

    Hi, can you please take a look at the screenshot and provide me some insight on this?

    If you look at row 2 to row 7, the Project ID is the same. How do I use VBA to fill the blank cells with S1 in column B and 2406269 in column C?

    Then if you look at row 8 to 19, the Project ID is the same as well. Now I need to fill those blank cells with S1 in column B and 281252 in column c? (Sometimes, quarter can be S2, but this screenshot doesn't include it.)

    Thank you very much.
    Attached Images Attached Images

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub SamT()
    Dim Rw as Long
    Dim IDStartRow As Long
    Dim IDEndRow As Long
    Dim QTRValue as String
    Dim AMTValue as Long
    
    IDstartRow = 2
    
    Do While Cells(1, IDStartRow).Value <> ""
    IDEndRow = IDStartRow
       'Get the real IDEndRow number
       Do until Cells(1, IDEndRow).Offset(1, 0).Value <> Cells(1, IDStartRow).Value
          IDEndRow = IDEndRow + 1
       Loop
    
      'Find the QTR value
      For Rw = IDStartRow to IDEndRow
          If Cells(Rw, 2).Value <> "" Then
             QTRValue = Cells(Rw, 2).Value
             AMTValue = Cells(Rw, 3).Value
    
            'assign the values here to insure a blank range will not be filled with false data.
             Range(Cells(2, IDStartRow), Cells(2, IDEndRow)).Value = QTRValue
             Range(Cells(3, IDStartRow), Cells(3, IDEndRow)).Value = AMTValue
    
             Exit For 'Or Goto label after Next Rw. See next comment.
          End If
      Next Rw
    
    IDStartRow = IDEndRow + 1
    End While ' Or Loop while, I forget and My "office" computer is down.
    
    End Sub
    Last edited by SamT; 12-01-2013 at 06:01 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    001.jpg

    Hi Sam. Thanks for your reply. I ran your codes, but the values were copied to the right. Please take a look at the screenshot. I'd appreciate if you could assist.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location


    Change these two lines
     Range(Cells(2, IDStartRow), Cells(2, IDEndRow)).Value = QTRValue 
                    Range(Cells(3, IDStartRow), Cells(3, IDEndRow)).Value = AMTValue
    To
    Range(Cells(IDStartRow, 2), Cells(IDEndRow, 2)).Value = QTRValue 
                    Range(Cells(Cells(IDStartRow, 3), Cells(IDEndRow, 3)).Value = AMTValue
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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