Offset Command?

CindyA

Board Regular
Joined
May 1, 2002
Messages
102
I have the following macro looking for the word "No" in column I.
After finding the word "No" I would like to have the macro move BELOW the cell in which the word "No" resides, and THEN insert a blank row. This code below finds the word "No" and inserts a blank row ABOVE that row; I need to insert the row below. I can't seem to find the proper code for "move 1 cell below before inserting a blank row". Thanks in advance.

*********************
Sub Test1()
Dim c As Range, myCount As Long, i As Long

myCount = Application.CountIf(Range("I1:I20000"), "No")

With Range("I1:I20000")
i = 1
Set c = .Find("No", LookIn:=xlValues)
If Not c Is Nothing Then
Do
c.EntireRow.Insert
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And i <= myCount
End If
End With

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Put this in to offset your cell.

ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate

HTH,
Colbymack
 
Upvote 0
Offset command?

I inserted the line you suggested as shown below. Doesn't do anything different. Did I put it in the wrong spot? I need to find the cell containing "No" and insert a blank row BELOW that row.

Thanks.
********************

Sub Test1()
Dim c As Range, myCount As Long, i As Long

myCount = Application.CountIf(Range("I1:I20000"), "No")

With Range("I1:I20000")
i = 1
Set c = .Find("No", LookIn:=xlValues)
If Not c Is Nothing Then
Do
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activatec.EntireRow.Insert
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And i <= myCount
End If
End With

End Sub
 
Upvote 0
Sorry - this was somewhat new to me, but I found that this should work for what you have asked about:

Sub Test1()
Dim c As Range, myCount As Long, i As Long

myCount = Application.CountIf(Range("I1:I20000"), "No")

With Range("I1:I20000")
i = 1
Set c = .Find("No", LookIn:=xlValues)
If Not c Is Nothing Then
Do
c.Resize(1, 1).Offset(1, 0).EntireRow.Insert
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And i <= myCount
End If
End With

End Sub
 
Upvote 0
Hello

I have refined the macro a little, please try out and see if it works a little better.

Code:
Sub Test1()
Application.ScreenUpdating = False
Dim mycount As Long
Dim oldsel As String
oldsel = ActiveCell.Address
mycount = Application.CountIf(Range("I1:I20000"), "No")
Range("I1").Select
On Error resume next
Do
    Range("I1:I20000").Find(What:="No", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
    ActiveCell.Offset(1, 0).EntireRow.Insert
    i = i + 1
    If Err <> 0 Then Exit Do
    ActiveCell.Offset(1, 0).Select
Loop Until i = mycount
Range(oldsel).Activate
Application.ScreenUpdating = True
End Sub

Hope this helps
 
Upvote 0
Fausto's solution is similar to the one I just posted, although Fausto's contains some error handling, which mine does not.

Good luck with either solution!
 
Upvote 0

Forum statistics

Threads
1,196,357
Messages
6,014,768
Members
441,847
Latest member
Linki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top