-
Code hangs if not find the any data in Master sheet
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.
[VBA]
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
[/VBA]
Thanks and Regards
FR
-
I usually do something like this
[VBA]
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
[/VBA]
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules