Run time error 450: Copying non zero values from non adjacent columns to another sheet (non adjacent columns)

JonathanSass

New Member
Joined
Apr 15, 2021
Messages
14
Office Version
  1. 2019
Hi all,

I have tried to use the following code for my issue described in the header:

VBA Code:
Sub CopyDataToJournal()

Dim erow As Long, lastrow As Long, i As Long

lastrow = Sheets("Sheet1").Cells(Rows.Count, 12).End(xlUp).Row

For i = 4 To lastrow
    If Sheet1.Cells(i, 12) <> "0" Then
    Sheets("Sheet1").Range(Cells(i, 12), Cells(i, 13), Cells(i, 17), Cells(i, 18), Cells(i, 19), Cells(i, 20)).Copy
    Sheets("JOURNAL").Activate
    erow = JOURNAL.Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row
    ActiveSheet.Paste Destination:=Sheets("JOURNAL").Range(Cells(erow, 1), Cells(erow, 2), Cells(erow, 6), Cells(erow, 7), Cells(erow, 8), Cells(erow, 9))
    Sheets("Sheet1").Activate
    End If
Next i
Application.CutCopyMode = False
   
End Sub

I am new to Excel VBA.

Thank you very much in advance!!
/Jonathan
 
Last edited by a moderator:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,547
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub CopyDataToJournal()

Dim erow As Long, lastrow As Long, i As Long

erow = Sheets("JOURNAL").Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row

With Sheets("Sheet1")
   lastrow = .Cells(Rows.Count, 12).End(xlUp).Row
   
   For i = 4 To lastrow
      If .Cells(i, 12) <> "0" Then
         .Cells(i, 12).Resize(, 2).Copy Sheets("Journal").Range("A" & erow)
         .Cells(i, 17).Resize(, 4).Copy Sheets("Journal").Range("F" & erow)
         erow = erow + 1
      End If
   Next i
End With
Application.CutCopyMode = False
   
End Sub
 

JonathanSass

New Member
Joined
Apr 15, 2021
Messages
14
Office Version
  1. 2019
Thank you for the reply but is doesnt work.

To explain a bit more I want to copy values from columns: 12,13,17,18,19,20 in the "Sheet1" to columns: 1,2,6,7,8,9 in "JOURNAL".

In these column there are some rows which have "0" as values. These I do not want to copy. Also the data has to be pasted as values.

Thank you very much in advance!
 

JonathanSass

New Member
Joined
Apr 15, 2021
Messages
14
Office Version
  1. 2019

ADVERTISEMENT

This time is gives me "424: Object required"
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,547
Office Version
  1. 365
Platform
  1. Windows
On which line?
 

JonathanSass

New Member
Joined
Apr 15, 2021
Messages
14
Office Version
  1. 2019

ADVERTISEMENT

On this one:
erow = Sheets("JOURNAL").Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,547
Office Version
  1. 365
Platform
  1. Windows
That should be Rows not Row
 

JonathanSass

New Member
Joined
Apr 15, 2021
Messages
14
Office Version
  1. 2019
Thanks! Now I get an error on this line:
.Cells(i, 12).Resize(, 2).Copy Sheets("Journal").Range("A" & erow)
1004: Application defined or Object defined error
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,547
Office Version
  1. 365
Platform
  1. Windows
Does it copy any data to the Journal sheet?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,553
Messages
5,636,982
Members
416,953
Latest member
broexc

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top