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:
VBA Code:
Sub Gratuit()

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

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

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

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Ok, how about
VBA Code:
erow = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0
Hi again

As it happens, I need the code to paste the values from column 17 with 2 decimal places exactly. I have tried with ROUND formula in the sheet, but it doesnt paste with two decimal places.

My code looks like this:

VBA Code:
Sub Gratuit()

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

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

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

Thanks in advance!
 
Upvote 0
It pastes with the value that was "before" the rounding (the cell is taking the value from a calculation in another cell). Sometimes this is without any decimals, and sometimes it is with one, two, three or four decimals
 
Upvote 0
If you have the round formula in col 17 then you will get the result of that formula.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

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
Back
Top