+ Reply to Thread
Results 1 to 2 of 2

read cell value on master, copy to matching sheet.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-26-2010
    Location
    NL
    MS-Off Ver
    Excel 2016
    Posts
    74

    read cell value on master, copy to matching sheet.

    Hello,

    I've got the following problem, I've got a sheet called "Invoer", here i've got 11 rows with data.
    (B4 till O14) where the values in column B match 11 other sheets.

    I'm trying to copy every row to its matching sheet. like this:

    Sub wegschrijven()
    
    If Blad1.Range("B4") = "Internet" Then
        Blad1.Range("B4:N4").Copy
        Blad2.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial
    End If
    
    If Blad1.Range("B4") = "Mail" Then
        Blad1.Range("B4:N4").Copy
        Blad3.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial
    End If
    
    etc
    etc
    etc
    
    End Sub
    But this will give me a very long macro, because the sorting and quantities can vary.
    I.ve attached an example so you can see what i mean.

    Is there a quicker way?

    Thanks in advance.

    ABBOV
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: read cell value on master, copy to matching sheet.

    Sub snb()
      sn = Sheets("Invoer").Cells(3, 2).CurrentRegion.Resize(, 14)
      For j = 2 To UBound(sn)
        Sheets(sn(j, 1)).Cells(Rows.Count, 2).End(xlUp).Offset(1, -1).Resize(, 14) = Application.Index(sn, j)
      Next
    End Sub
    PS. Do not use merged cells, VBA doesn't treat them correctly
    The setup of the 'invoer' sheet can be improved, so less code is required (structure precedes coding).
    Last edited by snb; 08-10-2011 at 06:53 AM.



+ 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