ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying an entire row (https://www.excelbanter.com/excel-programming/357631-copying-entire-row.html)

smitty24

Copying an entire row
 
I have an IF statement that compares a particular cell in two different
worksheets.

If Worksheets("sheet1").Cells(CountA, 1) =
Worksheets("sheet2").Cells(CountB, 1)

If my statement is true, how do I copy the entire row in which
cells(CountA,1) resides in on "sheet1" to a new worksheet "sheet3" in the row
that (CountA,1) is located on?

Thanks!

JMB

Copying an entire row
 
Worksheets("sheet1").Cells(CountA, 1).EntireRow.Copy _
Worksheets("sheet3").Cells(CountA, 1)


"smitty24" wrote:

I have an IF statement that compares a particular cell in two different
worksheets.

If Worksheets("sheet1").Cells(CountA, 1) =
Worksheets("sheet2").Cells(CountB, 1)

If my statement is true, how do I copy the entire row in which
cells(CountA,1) resides in on "sheet1" to a new worksheet "sheet3" in the row
that (CountA,1) is located on?

Thanks!


Rick Hansen

Copying an entire row
 
Here Smitty,

Here is some code that should get you started to slove your problem..

enjoy, Rick


Sub copyRow()
Dim countA As Long, countB As Long
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet

countA = 3
countB = 3
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Set ws3 = Worksheets("Sheet3")

If ws1.Cells(countA, 1) = ws2.Cells(countB, 1) Then
ws1.Range("A" & countA).EntireRow.Copy Destination:=ws3.Cells(countA, 1)
End If
End Sub




"smitty24" wrote in message
...
I have an IF statement that compares a particular cell in two different
worksheets.

If Worksheets("sheet1").Cells(CountA, 1) =
Worksheets("sheet2").Cells(CountB, 1)

If my statement is true, how do I copy the entire row in which
cells(CountA,1) resides in on "sheet1" to a new worksheet "sheet3" in the

row
that (CountA,1) is located on?

Thanks!





All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com