Consulting

Results 1 to 4 of 4

Thread: from mastersheet to other sheets (find the last blank raw)

  1. #1
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    2
    Location

    from mastersheet to other sheets (find the last blank raw)

    [COLOR=rgba(0, 0, 0, 0.87)]Hi,
    How can I change the code to move the data from the master sheet to the other sheets (and after the operation) to the last row it identifies as blank in each sheet
    thanks in advance,

    [/COLOR]
    Attached Files Attached Files

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Hi and welcome to the forum.

    That code copies the relevant data to the sheets but it doesn't clear old 'messed up' data. If that's what you want (but it's not that clear what you want), then add the line in red to the code:

        For i = 2 To UBound(myarr)
            ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
            If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
                Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
            Else
                Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
            End If
            Sheets(myarr(i) & "").ClearContents
            ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
        Next
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    2
    Location
    hi thanks for the help
    I will make it clear what I want. I don't want to erase old data. the data will be added to existing data in each sheets. for example, in the powerpiont sheet the last column used is 16 so the code will put the data in line 18 from the mastersheet. in access sheet the last columns used is 13 so the code will put data in line 15.
    thanks

    Quote Originally Posted by paulked View Post
    Hi and welcome to the forum.

    That code copies the relevant data to the sheets but it doesn't clear old 'messed up' data. If that's what you want (but it's not that clear what you want), then add the line in red to the code:

        For i = 2 To UBound(myarr)
            ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
            If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
                Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
            Else
                Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
            End If
            Sheets(myarr(i) & "").ClearContents
            ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
        Next
    Attached Files Attached Files
    Last edited by guylrb33; 04-16-2020 at 11:08 AM.

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Sub doll()
        Dim lr As Long, lrA As Long, lrE As Long, lrP As Long, i As Long
        Dim sh As Worksheet, shA As Worksheet, shE As Worksheet, shP As Worksheet
        
        Set sh = Sheets("master")
        Set shA = Sheets("access")
        Set shE = Sheets("excel")
        Set shP = Sheets("powerpoint")
        
        
        Application.ScreenUpdating = False
        
        lr = sh.Cells(Rows.Count, 1).End(3).Row
        lrA = shA.Cells(Rows.Count, 1).End(3).Row + 3
        lrE = shE.Cells(Rows.Count, 1).End(3).Row + 3
        lrP = shP.Cells(Rows.Count, 1).End(3).Row + 3
        
        For i = 2 To lr
            If sh.Cells(i, 1) = "access" Then
                sh.Rows(i).Copy shA.Cells(lrA, 1)
                lrA = lrA + 1
            End If
            If sh.Cells(i, 1) = "excel" Then
                sh.Rows(i).Copy shE.Cells(lrE, 1)
                lrE = lrE + 1
            End If
            If sh.Cells(i, 1) = "powerpoint" Then
                sh.Rows(i).Copy shP.Cells(lrP, 1)
                lrP = lrP + 1
            End If
        Next
    End Sub
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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