Copy and paste special in vba

gnara74

New Member
Joined
Sep 20, 2013
Messages
18
Hi All,
I'm trying to create a macro that should do the following things:
1. Look for a cell named "Pippo" (named through Name Manager) in the worksheet called "Pluto" or through the application vlookup
2. Copy the cell found (named Pippo) and paste it as link in the cell L11 of the sheet named "Topolino".

I'm pretty new with VBA and I created this macro but it doesn't work.

Sub BalancePrice3_Click()


Sheets("Pluto").Select
ActiveSheet.Range("Pippo").Select
Selection.Copy
Sheets("Topolino").Select
Range("L11").Select
ActiveSheet.Paste Link:=True
Sheets("Topolino).Application.Calculation = xlCalculationAutomatic

End Sub




Can anybody help me?
Would it be easier use VLookup in VBA?

It's pretty urgent!

Thanks :)

:confused::confused::confused:
 
Based on your initial post I simply named a cell somewhere on the Pluto sheet as Pippo. If you know the named range exists you don't need the VLOOKUP to find it.

Are you trying to make it so that a VLOOKUP is used to determine that the range you what is called Pippo?
Right, I've gone out on a limb here just in case you did want to use VLOOKUP to determine what named range is the one to be copied.

The amended macro to incorporate the result of a VLOOKUP as the desired named range to copy can be found below:

Rich (BB code):
Sub BalancePrice3_Click()
' Defines variable
Dim Rng As String
' Sets value of Rng as the result of your VLOOKUP
    Rng = Application.Evaluate("=VLOOKUP(""blu"",Pluto!$A$1:$O$16,13,FALSE)")
' Copies the named range that matches the VLOOKUP result
        Range(Rng).Copy
' Pastes link to cell L11 of Topolino sheet
            Sheets("Topolino").Select
                Range("L11").Select
                    ActiveSheet.Paste Link:=True
' Ensures calculation is set to Automatic
        Application.Calculation = xlCalculationAutomatic
End Sub

I have uploaded a simplified example workbook here. I have taken the liberty of naming another cell as Fishboy. If you change the "Pippo" cell in the lookup table to Fishboy and press the macro button you will see that it actually looks up the value and works out which cell to copy.

PS - Your original VLOOKUP was missing the final argument of True or False BTW
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The problem is that the vlookup is mandatory because the cell I refer to, it's not always in the same position.
Would it be possible to include the vlookup in the macro and then copy and paste as link in the other worksheet?
Thanks a lot for your help
 
Upvote 0
GREAT!!!!
I will test it right now and let you know!
Cell called Fishboy it's better than the one called Pippo :)
 
Upvote 0
The problem is that the vlookup is mandatory because the cell I refer to, it's not always in the same position.
Would it be possible to include the vlookup in the macro and then copy and paste as link in the other worksheet?
Thanks a lot for your help
See above :)
 
Upvote 0
Mmmm... no... there's something wrong.
I think it's easier of what you did.
The vlookup is necessary to find the cell in the 13th column (O) of a row, and I know the content of the first cell of this row (call it "blu")
Then, the cell found (that should be something like "O12" or "O13" or "O44" (every time the row changes), should be copy and paste as a link in another sheet.
 
Upvote 0
Mmmm... no... there's something wrong.
I think it's easier of what you did.
The vlookup is necessary to find the cell in the 13th column (O) of a row, and I know the content of the first cell of this row (call it "blu")
Then, the cell found (that should be something like "O12" or "O13" or "O44" (every time the row changes), should be copy and paste as a link in another sheet.
O is actually the 15th column, but I assume the 13th column of the lookup table?
 
Upvote 0
Yes... because it's M but it doesn't matter which column, it's something that I can change easily :)
the problem is that I'm not able to implement the vlookup - copy the cell of the result and paste it as link

Thanks for being so patient!
 
Upvote 0
Then, the cell found (that should be something like "O12" or "O13" or "O44" (every time the row changes), should be copy and paste as a link in another sheet.

gnara74, as well as the question below from Fishboy are you expecting the code to run when the result in your Vlookup changes?

Did you try out my test document?


This thread has grown a lot larger than I expected it to when I last looked. :ROFLMAO:
 
Upvote 0

Forum statistics

Threads
1,216,291
Messages
6,129,911
Members
449,540
Latest member
real_will_smith

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