Switch possible?

Gil149

Board Regular
Joined
Oct 11, 2010
Messages
144
I am using the code below to find something and offset the data. I am looking to change it a bit though...if the FindValue is not found I want to to find the last row and paste it one row lower. I can do the offsetting...I am stumped on the switching it to if it's not found, versus is found...thanks guys!

Code:
        For Each rngcell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
            FindValue = rngcell.Offset(0, 0).Value
                With Sheets("Resources").Range("A2:A" & Sheets("Resources").Range("A" & Rows.Count).End(xlUp).Row)
                    Set Rng = .Find(What:=FindValue, After:=.Cells(.Cells.Count), LookIn:=xlValues, LookAt:= _
                        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                    If Not Rng Is Nothing Then
                        FirstAddress = Rng.Address
                        Do
                            Rng.Row.Copy
                            Sheets("Resources").Range("A2:A" & Sheets("Resources").Range("A" & Rows.Count).End(xlUp).Row)(1).Paste
                            Set Rng = .FindNext(Rng)
                        Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
                    End If
                End With
        Next rngcell
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You can add an Else statement to your code to do something when no match for FindValue found.

Rich (BB code):
If Not Rng Is Nothing Then
   '-----do this if at least one instance of FindValue found
        FirstAddress = Rng.Address
        Do
           Rng.Row.Copy '???
           Sheets("Resources").Range("A2:A" & Sheets("Resources").Range("A" & Rows.Count).End(xlUp).Row)(1).Paste
            Set Rng = .FindNext(Rng)
        Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
Else
    '-----do this if no instances of FindValue found
'Your code here
End If

The code in red doesn't look correct.
Rng.Row will return a Row Number and you probably intend that to be a Range object such as Rng.EntireRow.

Once you have the Row copied, do you want to Paste it at the Top or Bottom?
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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