Copying an Array of cell values to another sheet

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
Hi everyone...I'm having trouble with the following code. My intent is to click on any cell in column "E" on activesheet, that will triger a "find" on sheet("SM") and copy the found value, plus the cell four to the "found cells" left and 6 cells to the its right. The vaslues in these 3 cells need to be copied to the target row on the activesheet in cells "A" "B" and "C"

Code:
Private Sub Lookup(Target As Range)
Application.ScreenUpdating = False
Dim pFind As Range
Set pFind = Sheets("SM").Range("E:E").find(What:=Target.Value, LookIn:=xlValues, LookAt:=xlPart)
If pFind Is Nothing Then MsgBox ("CD# not found on SM Sheet.")
If pFind Is Nothing Then Target.Offset(, -4).Interior.ColorIndex = 6
If pFind Is Nothing Then Exit Sub
[B]Set pFind = pFind.Array(Target.Offset(0, -4), Target, Target.Offset(0, 6)) [/B]'[U]it is hanging up here[/U]
Target.Value = pFind.Array.Value

'Range("A3").Activate
Application.ScreenUpdating = True
End Sub

I think the "array" is hanging me up and I do not know how to use it...or perhaps there is a better way.
Thanks for any help - Jim A
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
just fyi... you can do this...

Code:
If something Then
    'put lots of code here
    'as many lines as you need
End If

example...

Code:
If pFind Is Nothing Then
    MsgBox ("CD# not found on SM Sheet.")
    Target.Offset(, -4).Interior.ColorIndex = 6
    Exit Sub
End If

btw Find returns a range...

so what u want to do is... range1.Value = range2.Value

it will work fine if they are the same shape

you should always refer to the functions documentation on msdn if you never used... https://msdn.microsoft.com/en-us/library/office/ff839746.aspx

oh and btw... Range.Array does not exist... you need to refer to documentation... I would not rely on the excel devs to name things properly and make them intuitive lol
 
Last edited:
Upvote 0
OK..I acomplished what I wanted with 3 statements like:
Code:
Target.Offset(0,-1).value = pFind.Offset(0,-4).value
and so on.
I cleaned up my If Then statemnst too. I guess I just wanted to try something fancier.
Thanks - Jim A
 
Upvote 0
i will admit, putting single lines like you did is nicer to read but you are asking the cpu to do more work. For small macros and processes, it is irrelevant but you should always try to write efficient code. No prob, hope I helped.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,537
Members
449,316
Latest member
sravya

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