+ Reply to Thread
Results 1 to 4 of 4

VBA to copy/paste down values and stop at row with text

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    VBA to copy/paste down values and stop at row with text

    Hi all.
    File attached with dummy data.

    I have an export from our school data system with class codes/teacher and students.

    When it exported the data it only put the class code/teacher and ID on one row, then listed the students. I need the class code, teacher and ID on every row.

    So what I'm trying to do is to get:
    Copy the value in A2, B2, C2, E2, F2 and paste down in the empty cells the rows below

    STOP pasting when it reaches the row that has text (and the information from the next class) in this case that is row 26

    Then copy the values in A26, B26, C26, E26, F26 and paste down in the empty cells the rows below

    - Repeat that cycle throughout the sheet


    Classes vary in size so I can't say it will always be X number of rows to paste to.

    Is there way to set this up to do this? The report will be running frequently and there are over 1000 classes so manually isn't a viable option.

    I'd really appreciate any support you can give.

    Thanks

    Luke
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA to copy/paste down values and stop at row with text

    Select columns A to F, then goto Find & Select...Goto Special and select Blanks.

    Then in the formula bar put =A2 and confirm with CTRL+ENTER.

    Code.
    With Range("A:F")
        .SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C"
        .CurrentRegion.Value = .CurrentRegion.Value
    End With
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA to copy/paste down values and stop at row with text

    See next code
    Option Explicit
    
    Sub Treat()
    Dim WkRg  As Range
    Dim F  As Range
        Set WkRg = Range("A2:F" & Range("D" & Rows.Count).End(xlUp).Row)
        WkRg.Select
        For Each F In WkRg
            If F = "" Then F = F.Offset(-1, 0)
        Next
    End Sub
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA to copy/paste down values and stop at row with text

    Try this:-
    Sub MG26Jun45
    Dim Rng As Range, Dn As Range, T As Variant, T1 As Variant
    Set Rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Dn.Offset(, -3) > "" Then
            T = Application.Index(Dn.Offset(, -3).Resize(, 6), Array(1, 2, 3))
            T1 = Application.Index(Dn.Offset(, -3).Resize(, 6), Array(5, 6))
        Else
            Dn.Offset(, -3).Resize(, 3) = T
            Dn.Offset(, 1).Resize(, 2) = T1
        End If
    Next Dn
    End Sub
    Regards Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Stop overwriting cells - Copy and paste macro
    By juhaszp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2013, 05:37 PM
  2. [SOLVED] Cut, Copy or Paste causes excel to stop responding.
    By Jimizx in forum Excel General
    Replies: 2
    Last Post: 10-19-2012, 09:43 PM
  3. Replies: 0
    Last Post: 09-18-2012, 11:47 AM
  4. Stop users from Cut/Copy & Paste
    By rmcveigh in forum Excel General
    Replies: 2
    Last Post: 11-21-2006, 04:09 PM
  5. How to stop formulas from incrementing when you copy and paste?
    By Kirkwill in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2005, 02:06 PM

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