PDA

View Full Version : Code hangs if not find the any data in Master sheet



farrukh
01-09-2012, 07:22 AM
Hi All,

I have a code which works perfectly , but a little issue if code does not find any value or string in column be then hangs and keep inserting rows in other sheet to match the crieteria i need that the code run on used range of column B of maste sheet.




Sub InsertRowOnMatch()
Dim vM As Variant
Dim wks As Worksheet
Dim x As Long
With Worksheets("Master_sheet")
vM = .Range("B2:B" & .Range("B2").End(xlDown).Row)
End With
For Each wks In ThisWorkbook.Worksheets
If Left(wks.Name, 1) = "K" Then
For x = 1 To UBound(vM, 1)
If wks.Cells(x + 1, 2).Value <> vM(x, 1) Then
wks.Cells(x + 1, 2).EntireRow.Insert
End If
Next x
End If
Next
End Sub



Thanks and Regards
FR

Paul_Hossler
01-09-2012, 08:40 AM
I usually do something like this


Sub drv()
Dim rStart As Range, rEnd As Range
With Worksheets("Master_sheet")
Set rStart = .Cells(2, 2)
Set rEnd = .Cells(.Rows.Count, 2).End(xlUp)
End With
If rStart.Row <= rEnd.Row Then
MsgBox "OK"
Else
MsgBox "No Data"
End If
End Sub


Paul