VBA using find function and paste problem

constable

New Member
Joined
Sep 4, 2014
Messages
7
Hi All,

I am using the below code to go down a column of data and then perform a search in another tab, retrieving the matching data.

My problem occurs when I try to paste that piece of data in the same row as the search item but one column along. i.e. this piece of code >
Code:
[B].Range(ActiveCell) = HospFound[/B]

I have tried a few options and all seem to come up with an error. The only paste option that works is to select a specific range like this
Code:
[B].Range("A2") = hospfound[/B]
. This does work but I need the paste point to change.

The current error I am getting from the code below is "Application-defined or object-defined error"

Any help would be greatly appreciated!

Code:
[B]Sub NameMatch()[/B]

[B]Dim HospFound As Range, hospital As String, c As Range, n As Range[/B]


[B]For Each n In Range("AH2:AH2000")[/B]

[B]n.Select[/B]
[B]ActiveCell.Offset(0, 1).Select[/B]

[B]    Set c = Sheets("Proced Volumes").Range("L4:L500")[/B]

[B]    Set HospFound = c.Find(What:=n, After:=c.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)[/B]

[B]    If Not HospFound Is Nothing Then[/B]
[B]            With Worksheets("NHS Stated Volumes")[/B]
[B]            .Range(ActiveCell) = HospFound[/B]
[B]            End With[/B]
[B]    End If[/B]

[B]Next[/B]


[B]End Sub[/B]
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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