Hi Friends,
I am a beginer in VBA code. I am working as Field engineer in one firm. For my customer I need to get data for time spend by coverage time. SO I used for loop to get that details from sheet2("CovgDumb") data to sheet1("main") when I entered into coverage name.But if I keep any data in sheet1 except covearage name it will overwrite and paste entire row in sheet1 which I don't want.
When I call coverage name its only paste specific data which has value in CovgDumb file not any empty rows value nor even entire row.
It should only call specific rows which has data and it should not overwrite entire data.I am unable to selcet specific range to paste into sheet 2.Please help.
Sub Macro1()
'
' Macro1 Macro
'
' Copies corresponding item# rows from sheet1 worksheet
' to sheet2 worksheet by comparing item# column
If Range("AR6") = "" Then
Range("AR6").Select
MsgBox "Please enter a Coverage Name, then try again.", vbExclamation
Exit Sub
End If
Dim rng1 As Range, rng2 As Range
For Each rng1 In Worksheets("CovgDumb").Range("AR3").Resize(Worksheets("CovgDumb").Range("AR3").CurrentRegion.Rows.Count - 1).Rows
For Each rng2 In Worksheets("Main").Range("AR6").Resize(Worksheets("Main").Range("AR6").CurrentRegion.Rows.Count - 1).Rows
If rng2(1).Value = rng1(1).Value Then
rng1.EntireRow.Copy
rng2.EntireRow.PasteSpecial (xlPasteValues)
End If
Next rng2
Next rng1
Range("AR6").Select
End Sub
Bookmarks