VBA - conditional copy and paste

Rogerisit

Board Regular
Joined
Oct 20, 2016
Messages
70
Office Version
  1. 2019
Hi All, thanks again!

This code has issues! It was working until I expanded the conditions to add the AND and then expanded the copy range with the E:M.

Also, I want to reduce the number of rows looked at in my "lastrow" to use the one I have deactivated, which counts column h.

Any help appreciated.

ws.Activate
'lastrow = ws.Range("a1:a" & Range("h" & Rows.Count).End(xlUp).Row)
lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row
'input data
For i = 2 To lastrow
If ws.Range("a" & i).Value <> "" and_
ws.Range("i" & i).Value <> "0.00" then
ws.Range("A" & i & ":C" & i & ",E" &i&":m" &i).copy
SOP.Activate
lastrowrpt = SOP.Range("a" & Rows.Count).End(xlUp).Row
b = SOP.Cells(Rows.Count, 1).End(xlUp).Row
SOP.Range("a" & lastrowrpt + 1).Select
ActiveSheet.Paste


End If
Next i
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
It was working until I expanded the conditions to add the AND and then expanded the copy range with the E:M.
It was mainly a spacing issue. I also simplified that last part about lastrowrpt a little.
VBA Code:
    ws.Activate
    'lastrow = ws.Range("a1:a" & Range("h" & Rows.Count).End(xlUp).Row)
    lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row
    
    'input data
    For i = 2 To lastrow
        If ws.Range("a" & i).Value <> "" And _
            ws.Range("i" & i).Value <> "0.00" Then
            ws.Range("A" & i & ":C" & i & ",E" & i & ":M" & i).Copy
            SOP.Activate
            SOP.Range("a" & SOP.Rows.Count).End(xlUp)(2).Select
            ActiveSheet.Paste
        End If
    Next i
    Application.CutCopyMode = False

Also, I want to reduce the number of rows looked at in my "lastrow" to use the one I have deactivated, which counts column h.
I don't understand what you are trying to do here.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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