anrion
Goto Top

Reihenauswahl zur Copy-Aussage hinzufügen

Hallo Community,

ich habe meine Datei mit diesem Code bestückt:

.Columns(Spalte).Copy Destination:=Tabelle2.Columns(Cells(10, 2))

Ich möchte aber nicht die gesamte Spalte kopieren, sondern bloß Reihe 1-8.

Kann mir bitte jemand helfen?

mfG Stefan

Content-Key: 311751

Url: https://administrator.de/contentid/311751

Ausgedruckt am: 28.03.2024 um 22:03 Uhr

Mitglied: 129813
129813 04.08.2016 um 14:25:29 Uhr
Goto Top
.Range(.Cells(1,Spalte),.Cells(8,Spalte)).Copy Destination:=Tabelle2.Columns(Cells(10, 2))
Regards
Mitglied: 116301
116301 04.08.2016 um 14:33:14 Uhr
Goto Top
Hallo zusammen!

oder:
.Cells(1,Spalte).Resize(8,1).Copy Destination:=Tabelle2.Columns(Cells(10, 2))

Grüße Dieter
Mitglied: Anrion
Anrion 05.08.2016 um 08:01:32 Uhr
Goto Top
Hi,

Danke für die schnellen Antworten.
Thanks for the fast answers I appreciate it.

Aber es kommt bei beiden die Fehlermeldung:
Die Copy-Methode des Range-Objektes konnte nicht ausgeführt werden.

In case of both codes there is this Bug:
The Copy-Method of the range-object could not become executed

Grüße
Regards

Stefan
Mitglied: 129813
129813 05.08.2016 aktualisiert um 08:49:55 Uhr
Goto Top
Hi, you posted not enough of your code. You should check your destination cell, you are defining a column as a target, better use a single cell as target. Are there hidden cells/rows in source or destination?

Please provide us with more information about your sheet and environment, thank you ...
Mitglied: Anrion
Anrion 05.08.2016 aktualisiert um 09:03:01 Uhr
Goto Top
Hey highload,

sure I unterstand, there's the code ;)

Sub BedingteKopieSpalten()

'Defintion der Variablen und Werte  
Dim Spalte  As Long
Dim SpalteMax As Long
Dim n As Long
With Tabelle1
SpalteMax = .UsedRange.Columns.Count
For Spalte = 3 To SpalteMax
n = 0

'Bedingung zum Kopieren und Löschen  
If .Cells(10, 3).Value = 1 Then

'Kopier- und Löschvorgang  
Application.Wait Now + TimeSerial(0, 0, n)
.Columns(3).Copy Destination:=Tabelle2.Columns(Cells(10, 2))
Application.Wait Now + TimeSerial(0, 0, n)
Cells(10, 2) = Cells(10, 2) + 1
Application.Wait Now + TimeSerial(0, 0, n)
Columns(3).Delete

On top is table 1 and bottom table 2.
123
Mitglied: 129813
Lösung 129813 05.08.2016 um 09:34:14 Uhr
Goto Top
tabelle1 and Tabelle2 ??
You have to use this format Sheets("Tabelle1"), or did you define these variables anywhere else ?

I would do it like this
Sub BedingteKopieSpalten()
    Dim rngDel as Range, i as long
    With Sheets("Tabelle1")  
        For i = 3 to .UsedRange.Columns.Count
            if .Cells(10,i).Value = 1 then
                .Cells(1,i).Resize(8,1).Copy Destination:=Sheets("Tabelle2").Cells(2, Columns.Count).End(xlToLeft).Offset(-1,1)  
                If not rngDel is Nothing then
                    set rngDel = Union(rngDel, .Cells(1,i).EntireColumn)
                Else
                    set rngDel = .Cells(1,i).EntireColumn
                End if 
            End if
        Next
    End with
    If not rngDel is Nothing rngDel.Delete
End Sub