'Copy entire rows based on multiple values
My first sheet is the template were all the values will be put in by the user.
The second sheet is where I want the information copied to.
I created a CommandButton that copies over the first lot of information (that is the Company logo, Company info and Client inf).
My second CommandButton is where my problem starts.
I have entire rows to copy based on the value in column "O".
If Column "O" is >= 1 OR if Column "O" has an "x" then that row should be copied. So far it copies the "x" over without a specific line of code stating that.
-When I run the code it starts copying to row 1. I need it to start copying to row 34
-If the value in column "O" is "x" then it copies that row but then it copies the next row over that previous one, it does not move to the next row. However when it copies over rows with values >1 then it moves to the next row and copies that.
'Sheet1 is named Template1
'Sheet2 is named Copy data
a = Worksheets("Template1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 34 To a
If Worksheets("Template1").Cells(i, 15) >= 1 Then
Worksheets("Template1").Rows(i).Copy
Worksheets("Copy data").Activate
B = Worksheets("Copy data").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Copy data").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Template1").Activate
End If
Next
Apllication.CutCopyMode = False
ThisWorkbook.Worksheets("Template1").Cells(1, 1).Select
Solution 1:[1]
Hopefully it benefits your business
Dim lr As Integer, alan As Range
Dim sa1 As Worksheet, sa2 As Worksheet
Dim i As Integer
Set sa1 = Worksheets("Template1")
Set sa2 = Worksheets("Copy data")
lr = sa1.Cells(Rows.Count, 1).End(xlUp).Row
Set alan = sa1.Range("A34", "O" & lr)
For i = 34 To alan.Rows.Count + 34
If sa1.Cells(i, 15) >= 1 Or sa1.Cells(i, 15) = "x" Then
sa1.Range("a" & i).Resize(, alan.Columns.Count).Copy _
sa2.Range("A" & sa2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)
End If
Next i
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MurtiCom |
