Een aantal regels kopieren naar een ander tabblad

Anoniem
2024-06-05T14:07:18+00:00

Ik heb een bestelbon gemaakt waaruit ik een pakbon wil samenstellen met de artikelen die besteld zijn.

De gegevens staan op tabblad "Bon voor klant" vanaf rij 11, en in kolom B,C,D,E en G

In kolom G staat het aantal en alleen als er daar een aantal staat moet deze regel komen op tabblad "Pakbon"

in een formule zou je zoiets kunnen doen met =ALS(G11>0;"groter dan 0";"kleiner dan 0") om te kijken of er een aantal is ingevuld.

Ik denk dat dit alleen met een macro te doen is, hier weet ik nog niet zoveel van, wel steeds meer...

misschien dat er hier iemand is die me wat op weg kan helpen.

Microsoft 365 en Office | Excel | Voor thuisgebruik | Windows

Vergrendelde vraag. Deze vraag is gemigreerd vanuit de Microsoft Ondersteuning-community. U kunt met een stem aangeven of de inhoud nuttig is, maar u kunt geen opmerkingen of antwoorden toevoegen of de vraag volgen.

0 opmerkingen Geen opmerkingen
Antwoord geaccepteerd door vraagauteur
Anoniem
2024-06-06T15:29:23+00:00

Dit antwoord is automatisch vertaald. Als gevolg hiervan kunnen er grammaticale fouten of vreemde formuleringen zijn.

Hoi, Richard Hs

U kunt de volgende code proberen. Let op, zorg ervoor dat Blad1 en Blad2 bestaan.

    Dim wsSource As Worksheet

    Dim wsDestination As Worksheet

    Dim lastRow As Long

    Dim i As Long

    Dim destRow As Long

    ' Define the source and destination worksheets

    Set wsSource = ThisWorkbook.Sheets("Sheet1") ' Assuming the original sheet name is "Sheet1"

    Set wsDestination = ThisWorkbook.Sheets("Sheet2") ' Assuming the destination sheet name is "Sheet2"

    ' Get the last row of the source worksheet

    lastRow = wsSource.Cells(wsSource.Rows.Count, "G").End(xlUp).Row

    ' Initialize destination row

    destRow = 1

    ' Loop through the rows of the source worksheet

    For i = 11 To lastRow

        ' Check if the value in the "G" column is greater than 0

        If wsSource.Cells(i, "G").Value > 0 Then

            ' Clear the destination row before copying

            wsDestination.Rows(destRow).Clear

            ' Copy the row to the destination worksheet if it meets the condition

            wsSource.Rows(i).Copy Destination:=wsDestination.Rows(destRow)

            destRow = destRow + 1

        End If

    Next i

End Sub

Deze kant is getest zonder afwijkingen, maar ik weet niet zeker of deze aan uw eisen voldoet, dus als dat niet het geval is, raad ik u aan enkele voorbeelden van gegevenslocaties in Excel te illustreren en vervolgens screenshots en meer gedetailleerde beschrijvingen te maken, zodat we uw probleem gemakkelijker kunnen begrijpen.

We kijken uit naar uw antwoord.

Hartelijke groeten

Yujun.F-MSFT | Ondersteuningsspecialist voor de Microsoft-community

Was dit antwoord nuttig?

1 persoon vond dit antwoord nuttig.
0 opmerkingen Geen opmerkingen

6 extra antwoorden

Sorteren op: Nieuwste
  1. Anoniem
    2024-09-13T14:25:49+00:00

    Het vreemde is nu opeens dat als ik de pakbon maak, hij kijkt naar het eerste artikel en deze gegevens kopieert, met het aantal van het artikel wat besteld is.

    Hij kopieert dus rij 10 terwijl er een aantal in rij 14 is ingevuld. Cel G10 is dus <0 en zou hij moeten negeren, Cel G14 is >0

    De pakbon zou dus moeten zijn:

    Stoepenplaat Grijs 2

    maar ik krijg dit:

    Abri's Enkel  (zonder planken/glas) Grijs 2

    https://docs.google.com/spreadsheets/d/1PXVkmpy7xxQ3tS4yszezJaDKrduE8TiN/edit?usp=sharing&ouid=116327367937524882702&rtpof=true&sd=true

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  2. Anoniem
    2024-06-08T11:44:54+00:00

    Nog even een aanvullende vraag.

    Ik heb het inmiddels zelf opgelost maar ben benieuwd naar jouw antwoord hierop:

    Ik zou alleen de cellen A,B,C,D,E en G willen kopieren en niet de cellen F en H, en de opmaak hoeft ook niet mee.

    Ik heb het op deze manier opgelost:

    Worksheets("Pakbon").Select

            Range("F11:H100").Borders.LineStyle = xlNone 
    
            Range("F11:F100").ClearContents 
    
            Range("H11:H100").ClearContents
    

    Ook zoek ik nog een mogelijkheid deze pakbon als PDF af te drukken.

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  3. Anoniem
    2024-06-06T20:32:44+00:00

    Dit antwoord is automatisch vertaald. Als gevolg hiervan kunnen er grammaticale fouten of vreemde formuleringen zijn.

    Hallo

    Ik ben erg blij dat uw probleem goed is opgelost.

    Voel je vrij om opnieuw te posten als je in de toekomst nog andere vragen hebt.

    Hartelijke groeten

    Yujun.F-MSFT | Ondersteuningsspecialist voor de Microsoft-community

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen
  4. Anoniem
    2024-06-06T19:35:50+00:00

    Sub Pakbon()

    Dim wsSource As Worksheet 
    
    Dim wsDestination As Worksheet 
    
    Dim lastRow As Long 
    
    Dim i As Long 
    
    Dim destRow As Long 
    
    ' Define the source and destination worksheets 
    
    Set wsSource = ThisWorkbook.Sheets("Bon voor klant") ' Assuming the original sheet name is "Sheet1" 
    
    Set wsDestination = ThisWorkbook.Sheets("Pakbon") ' Assuming the destination sheet name is "Sheet2" 
    
    ' Get the last row of the source worksheet 
    
    lastRow = wsSource.Cells(wsSource.Rows.Count, "G").End(xlUp).Row 
    
    ' Initialize destination row 
    
    destRow = 1 
    
    ' Loop through the rows of the source worksheet 
    
    For i = 11 To lastRow 
    
        ' Check if the value in the "G" column is greater than 0 
    
        If wsSource.Cells(i, "G").Value &gt; 0 Then 
    
            ' Clear the destination row before copying 
    
            wsDestination.Rows(destRow).Clear 
    
            ' Copy the row to the destination worksheet if it meets the condition 
    
            wsSource.Rows(i).Copy Destination:=wsDestination.Rows(destRow) 
    
            destRow = destRow + 1 
    
        End If 
    
    Next i 
    

    End Sub

    dit werkt.

    Bedankt voor deze oplossing.

    Was dit antwoord nuttig?

    0 opmerkingen Geen opmerkingen