+ Reply to Thread
Results 1 to 33 of 33

adding text to row a b and c while looping

Hybrid View

rjhe22 adding text to row a b and c... 01-13-2013, 02:57 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 03:26 PM
OllieB Re: adding text to row a b... 01-13-2013, 03:31 PM
OllieB Re: adding text to row a b... 01-13-2013, 03:32 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 03:37 PM
OllieB Re: adding text to row a b... 01-13-2013, 03:38 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 03:41 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 03:38 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 03:45 PM
OllieB Re: adding text to row a b... 01-13-2013, 03:52 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 04:02 PM
OllieB Re: adding text to row a b... 01-13-2013, 04:05 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 04:14 PM
OllieB Re: adding text to row a b... 01-13-2013, 04:16 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 04:19 PM
OllieB Re: adding text to row a b... 01-13-2013, 04:25 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 04:36 PM
OllieB Re: adding text to row a b... 01-13-2013, 04:47 PM
rjhe22 Re: adding text to row a b... 01-13-2013, 04:49 PM
OllieB Re: adding text to row a b... 01-14-2013, 03:06 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 04:43 AM
OllieB Re: adding text to row a b... 01-14-2013, 06:25 AM
OllieB Re: adding text to row a b... 01-14-2013, 06:02 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 06:13 AM
OllieB Re: adding text to row a b... 01-14-2013, 06:19 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 06:23 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 06:24 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 06:26 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 07:02 AM
OllieB Re: adding text to row a b... 01-14-2013, 07:07 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 07:54 AM
OllieB Re: adding text to row a b... 01-14-2013, 08:05 AM
rjhe22 Re: adding text to row a b... 01-14-2013, 08:06 AM
  1. #1
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    adding text to row a b and c while looping

    hi
    i have this code that copys and past stuff from another workbook and paste what i want from that work book to another work book in row d and e

    what i need is to add the same words to rows a b and c while its copying over my info from other sheet
    here is the code where it copies and paste the info over
    Sub Gross_NAV()
    Dim i As Long, LR As Long
    
        Dim AR As Long
        Dim dAveragePrep As Double
        Dim rng As Range
        Dim ang As Long
        Application.ScreenUpdating = False
    On Error Resume Next
         Set ms = Workbooks("Book4.xlsx").Sheets("NOK IA1")
        With Worksheets("Allocation")
    
            LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
              For i = 1 To LR
                 If IsDate(.Cells(i, 1)) Then
                     .Cells(i, 1).Copy
                    MyDate = ms.Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial(xlPasteValues)
                    MyDate.NumberFormat = "dd/mm/yyyy"
                End If
                    If UCase$(.Cells(i, AG).Value) = "Gross NAV" And UCase$(.Cells(i, C).Value) = "NOK/IA1" Then
                                                  
                    .Cells(i, "AG").Offset(1).Resize(1).Copy
                    
                    MyData = Format(ms.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial(Transpose:=True), Percent)
                        
         
    
                   
                  End If
              Next i
              End With
              
    
    Application.CutCopyMode = 0
    
    Application.ScreenUpdating = True
    
    End Sub
    is it possible to add text to the other rows while this is looping through and adding to sheet

    if so can anyone help

  2. #2
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    also code doesnt seem to work right

    what i want to happen is if i find the work gross nav in column ai and the word nok/ai in row c then copy the figure from row ai

    anyone any ideas why this cod wont work

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I assume you want to write values to specific cells on the "NOK IA1" worksheet? The current process pastes the information in the target workbook on the current lastrow + 1 (determined separately for both column E and E). So if for eample you would like to write something to columns A and B you could insert the following code just before the Next i statement

    ' insert this row along with the other declarations
        dim LastNOKRow as Long
    
    ' write to column A and B
        LastNOKRow=ms.cells(rows.count,"A").End(xlup).Row +1
        ms.cells(LastNOKRow,"A").Value = "Something into column A"
        ms.cells(LastNOKRow,"B").Value = "Something into column B"
    or alternatively

    ms.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = "something in column A"
    ms.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = "something in column B"
    If you like my contribution click the star icon!

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I assume you want to write values to specific cells on the "NOK IA1" worksheet? The current process pastes the information in the target workbook on the current lastrow + 1 (determined separately for both column E and E). So if for eample you would like to write something to columns A and B you could insert the following code just before the Next i statement

    ' insert this row along with the other declarations
        dim LastNOKRow as Long
    
    ' write to column A and B
        LastNOKRow=ms.cells(rows.count,"A").End(xlup).Row +1
        ms.cells(LastNOKRow,"A").Value = "Something into column A"
        ms.cells(LastNOKRow,"B").Value = "Something into column B"
    or alternatively

    ms.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = "something in column A"
    ms.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = "something in column B"

  5. #5
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    that great thank

    would u no any reason why the above code wouldnt pick the value i want if it find the text gross nav in one column and nok/ai in another column

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    Try replacing

         If UCase$(.Cells(i, AG).Value) = "Gross NAV" And UCase$(.Cells(i, C).Value) = "NOK/IA1" Then
              .Cells(i, "AG").Offset(1).Resize(1).Copy
              MyData = Format(ms.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial(Transpose:=True), Percent)
         End If
    by

         If UCase$(.Cells(i, AG).Value) = "Gross NAV" And UCase$(.Cells(i, C).Value) = "NOK/IA1" Then
              ms.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Value = .Cells(i, "AI").Value
         End If

  7. #7
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    still seems to be picing up all figures and not just the 1 figure

  8. #8
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    will try that thanks

  9. #9
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    does this code make it look for just the whole word
    nok/a1

    as under that i have
    nok/a1a
    nok/a2
    nok/a2a

    so maybe thats causing the problem

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I found your problem. replace the code with

    If UCase$(.Cells(i, "AG").Value) = "Gross NAV" And UCase$(.Cells(i, "C").Value) = "NOK/IA1" Then
              ms.Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Value = Format(.Cells(i, "AI").Value,Percent)
         End If
    You forgot the quotes around the column names AG and C, and I forgot the Format as percent. Because you have on error resume next, it skipped your IF statement and always conducted the update.
    Last edited by OllieB; 01-13-2013 at 03:54 PM.

  11. #11
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    what im trying to do

    is copy certain info from one book to another book.
    the figure i want is under the column ai
    but it can only be the figure from column c that has the words NOK/IA1

    here is a n example of the speard sheet
    01/11/2012		
    		
    Partnership Code	Class Code	 Gross NAV 
    UBSUCITS	        NOK/IA1	            -   
    UBSUCITS	        NOK/IA2	         29,034,655.35 
    UBSUCITS	        NOK/RA1	         106,559,564.24 
    UBSUCITS	        NOK/RA2	         4,593,723.09
    so i the figure from the gross nav column where NOK/IA1 from the class code or column c

  12. #12
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I think this may the code you are looking for

    Sub Gross_NAV()
    On Error Resume Next
    
    '#
    '# declare
    '#
         Dim lngRowNumber As Long
         Dim xlsTarget As Excel.Worksheet
         Dim lngTargetRow As Long
        
    '#
    '# block application interface updating for performance reasons
    '#
          Application.ScreenUpdating = False
          
    '#
    '# initialise
    '#
         Set xlsTarget = Workbooks("Book4.xlsx").Worksheets("NOK IA1")
         
    '#
    '# process all rows from the allocation worksheet
    '#
         With Thiswork.Worksheets("Allocation")
              For lngRowNumber = 1 To .UsedRange.Rows.Count
              
              '#
              '# get the last row on the target worksheet and add 1 count in case
              '# new values are to be written
              '#
                   lngTargetRow = xlsTarget.UsedRange.Rows.Count + 1
                   
              '#
              '# if the value if column1 is a valid date, copy the date to the ms worksheet
              '#
                   If IsDate(.Cells(lngRowNumber, 1).Value) Then
                        .Cells(lngTargetRow, "D").Value = .Cells(lngRowNumber, "A").Value
                        .Cells(lngTargetRow, "D").NumberFormat = "dd/mm/yyyy"
                   End If
                   
              '#
              '# if  column C holds NOK/IA1 then the value of column AI should be copied into column E on the target worksheet
              '#
                   If UCase$(.Cells(i, C).Value) = "NOK/IA1" Then
                        .Cells(lngTargetRow, "E").Value = Format(.Cells(lngRowNumber, "AI").Value, Percent)
                   End If
                   
              Next lngRowNumber
         End With
         
    '#
    '# restore application user interface
    '#
         Application.ScreenUpdating = True
    
    End Sub

  13. #13
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    that doesnt seem to work

    and the example i gave just had 1 date in my sheet could have many so i need my looping around

    is there a way of keeping my code and just changing the bit where its picking up the line to copy over

  14. #14
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    Sorry, few typing errors

    try below code
    Sub Gross_NAV()
    On Error Resume Next
    
    '#
    '# declare
    '#
         Dim lngRowNumber As Long
         Dim xlsTarget As Excel.Worksheet
         Dim lngTargetRow As Long
        
    '#
    '# block application interface updating for performance reasons
    '#
          Application.ScreenUpdating = False
          
    '#
    '# initialise
    '#
         Set xlsTarget = Workbooks("Book4.xlsx").Worksheets("NOK IA1")
         
    '#
    '# process all rows from the allocation worksheet
    '#
         With ThisWorkbook.Worksheets("Allocation")
              For lngRowNumber = 1 To .UsedRange.Rows.Count
              
              '#
              '# get the last row on the target worksheet and add 1 count in case
              '# new values are to be written
              '#
                   lngTargetRow = xlsTarget.UsedRange.Rows.Count + 1
                   
              '#
              '# if the value if column1 is a valid date, copy the date to the ms worksheet
              '#
                   If IsDate(.Cells(lngRowNumber, 1).Value) Then
                        .Cells(lngTargetRow, "D").Value = .Cells(lngRowNumber, "A").Value
                        .Cells(lngTargetRow, "D").NumberFormat = "dd/mm/yyyy"
                   End If
                   
              '#
              '# if column C holds NOK/IA1 then the value of column AI should be copied into column E on the target worksheet
              '#
                   If UCase$(.Cells(lngRowNumber, "C").Value) = "NOK/IA1" Then
                        .Cells(lngTargetRow, "AI").Value = Format(.Cells(lngRowNumber, "A").Value, "Percent")
                   End If
                   
              Next lngRowNumber
         End With
         
    '#
    '# restore application user interface
    '#
         Application.ScreenUpdating = True
    
    End Sub

  15. #15
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    seems to lopp through it all right
    but its not printing it to the worksheet in workbook

  16. #16
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    Last attempt. Try the below code
    Sub Gross_NAV()
    On Error Resume Next
    
    '#
    '# declare
    '#
         Dim lngRowNumber As Long
         Dim xlsTarget As Excel.Worksheet
         Dim lngTargetRow As Long
        
    '#
    '# block application interface updating for performance reasons
    '#
          Application.ScreenUpdating = False
          
    '#
    '# initialise
    '#
         Set xlsTarget = Workbooks("Book4.xlsx").Worksheets("NOK IA1")
         
    '#
    '# process all rows from the allocation worksheet, when column C holds the value NOK/IA1
    '# copy information to the target worksheet
    '#
         With ThisWorkbook.Worksheets("Allocation")
              For lngRowNumber = 1 To .UsedRange.Rows.Count
                   If UCase$(.Cells(lngRowNumber, "C").Value) = "NOK/IA1" Then
                        lngTargetRow = xlsTarget.UsedRange.Rows.Count + 1
                        .Cells(lngTargetRow, "D").Value = .Cells(1, 1).Value
                        .Cells(lngTargetRow, "D").NumberFormat = "dd/mm/yyyy"
                        .Cells(lngTargetRow, "E").Value = Format(.Cells(lngRowNumber, "AI").Value, "Percent")
                   End If
              Next lngRowNumber
         End With
         
    '#
    '# restore application user interface
    '#
         Application.ScreenUpdating = True
    
    End Sub
    If this does not work you will have to post copies of your workbooks.
    Last edited by OllieB; 01-13-2013 at 04:30 PM.

  17. #17
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    hi
    no still not writing to new workbook
    please find attached copy of the work books

    FND November 2012.xlsm
    Book4.xlsx

  18. #18
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I will look at it tommorow. Is book4 open while you are running the code or are you assuming this code will open and save the workbook as well?

  19. #19
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    book 4 is open

    ill have to try solve this tonight myself as has to be done for tomorrow.

    thanks very much for all the help

  20. #20
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I tried to have a look, but I am not able to download the file as I get a password protected message

  21. #21
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    HI
    try this book
    Book1.xlsx

  22. #22
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    Ok. I have renamed the target workbook to Allocation, as that makes more sense to me. When you run the macro it will prompt you to select the FND November workbook. It will loop through all records identifying the sections (starting with a date) and for the records in that section will search for NOK/IA1 in column C. When found, it will add a record to the Allocation worksheet with the date in column A and the value of column AI in column B. Feel free to change this to meet you needs. Note that in the example provided column AI contain the value ZERO for every NOK/IA1 record.
    Attached Files Attached Files

  23. #23
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I have looked at the workbooks provided and the description of your requirements, and they are quite confusing. For example column AG does not hold the description Gross NAV at all, column AI is supposed to be formatted as a percentage, but in fact contains an amount. The date you want to copy is not stored on the row itself, but at the beginning of a section. etc etc

    - Do you want to copy information from "book1" (worksheet Sheet1) to "FND November" (worksheet Allocation)?
    - which columns do you want to copy and where should the copied information be placed on the target worksheet?
    - When do you want to copy the information (i.e. the condition)

  24. #24
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    hi

    sorry that was me not fixing the code.
    -its going to go from "fnd november" to book 4 but as the fun november book is password protected i just copied and pasted it into book 1.
    so for this exmaple go from book 1 to book 4
    - i want to copy the value under the gross nav where in row c it has NOK/IA1
    - i want to copy it even time i run macro

  25. #25
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    I have looked at the workbooks provided and the description of your requirements, and they are quite confusing. For example column AG does not hold the description Gross NAV at all, column AI is supposed to be formatted as a percentage, but in fact contains an amount. The date you want to copy is not stored on the row itself, but at the beginning of a section. etc etc

    - Do you want to copy information from "book1" (worksheet Sheet1) to "FND November" (worksheet Allocation)?
    - which columns do you want to copy and where should the copied information be placed on the target worksheet?
    - When do you want to copy the information (i.e. the condition)

  26. #26
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    - Do you want to copy information from "book1" (worksheet Sheet1) to "FND November" (worksheet Allocation)?
    no lets copy it from "book1" (worksheet Sheet1) to book4 (worksheet NOK IA1)

    - which columns do you want to copy and where should the copied information be placed on the target worksheet?
    i want to copy the figure under gross nav column c = NOK IA1 and i want the date to be added to row d and the vaule it pick to be added to row d

    - When do you want to copy the information (i.e. the condition)
    every time i run macro i want to it copy and paste over

  27. #27
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    - Do you want to copy information from "book1" (worksheet Sheet1) to "FND November" (worksheet Allocation)?
    no lets copy it from "book1" (worksheet Sheet1) to book4 (worksheet NOK IA1)

    - which columns do you want to copy and where should the copied information be placed on the target worksheet?
    i want to copy the figure under gross nav column c = NOK IA1 and the date from first column.i want the date to be added to row d and the vaule it pick to be added to row d

    - When do you want to copy the information (i.e. the condition)
    every time i run macro i want to it copy and paste over

  28. #28
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    thanks will have a look at that
    again thanks very much for all help

  29. #29
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    that worked
    again seriously thanks

  30. #30
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    Glad to hear.

    Will you please remember to mark this thread as SOLVED, and click on the star icon if you are happy with my contribution. Thank you.

  31. #31
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    hi
    do u think there is a way of improving this code
    Sub FUND_OWNERSHIP()
    Dim i As Long, LR As Long
    
        Dim AR As Long
        Dim dAveragePrep As Double
        Dim rng As Range
        Dim ang As Long
        Application.ScreenUpdating = False
    On Error Resume Next
         Set ms = Workbooks("Book4.xlsx").Sheets("Allocation")
        With Worksheets("Allocation")
    
            LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
              For i = 1 To LR
                 If IsDate(.Cells(i, 1)) Then
                     .Cells(i, 1).Copy
                    MyDate = ms.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial(xlPasteValues)
                    MyDate.NumberFormat = "dd/mm/yyyy"
                End If
                    If UCase$(.Cells(i, 30).Value) = "FUND OWNERSHIP %" Then
                                                  
                    .Cells(i, "AD").Offset(1).Resize(4).Copy
                    
                    MyData = Format(ms.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial(Transpose:=True), Percent)
                        
         
    
                   
                  End If
              Next i
              End With
              
     Dim ws As Worksheet: Set ws = Workbooks("Book4.xlsx").Sheets("Allocation")
        With ws
            Set rng = .Range(.Range("B2"), .Range("B" & Rows.Count).End(xlUp))
            dAveragePrep = WorksheetFunction.Average(rng)
            ang = .Range("B" & Rows.Count).End(xlUp).Row + 1
            .Range("B" & ang) = dAveragePrep
        End With
    With ws
            Set rng = .Range(.Range("C2"), .Range("C" & Rows.Count).End(xlUp))
            dAveragePrep = WorksheetFunction.Average(rng)
            ang = .Range("C" & Rows.Count).End(xlUp).Row + 1
            .Range("C" & ang) = dAveragePrep
        End With
        With ws
            Set rng = .Range(.Range("D2"), .Range("D" & Rows.Count).End(xlUp))
            dAveragePrep = WorksheetFunction.Average(rng)
            ang = .Range("D" & Rows.Count).End(xlUp).Row + 1
            .Range("D" & ang) = dAveragePrep
        End With
           With ws
            Set rng = .Range(.Range("E2"), .Range("E" & Rows.Count).End(xlUp))
            dAveragePrep = WorksheetFunction.Average(rng)
            ang = .Range("E" & Rows.Count).End(xlUp).Row + 1
            .Range("E" & ang) = dAveragePrep
        End With
        ms.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = "average"
    Application.CutCopyMode = 0
    
    Application.ScreenUpdating = True
    
    End Sub
    what its doing is looking for column ad or fund ownership copying and pasting the 4 line of figures under that column header

  32. #32
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: adding text to row a b and c while looping

    pls open a new thread for this request as it is not allowed (forum rules) to raise a new request in an existing thread. When you do raise a new thread, please ensure that your request is clearly formulated.

  33. #33
    Registered User
    Join Date
    12-19-2012
    Location
    dublin ireand
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: adding text to row a b and c while looping

    ok sorry forgot

+ 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