Solved

Macro - Paste Special using indirect?  Excel VBA

Posted on 2011-02-16
2
578 Views
Last Modified: 2012-05-11
See code below.

Columns("B:B").Select

I do NOT want to Select Column "B" specifically.

I actually want to Specify the column that is indicated by the contents of cell A10.

So, for example, if A10 contains "X" then I want: Columns("X:X").Select
So, for example, if A10 contains "Z" then I want: Columns("Z:Z").Select


How do I do this?

Thanks,

Sub Macro2()
'
' Macro2 Macro
'
    Columns("B:B").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
...
...
...

Open in new window

0
Comment
Question by:Patrick O'Dea
2 Comments
 
LVL 6

Accepted Solution

by:
FernandoFernandes earned 500 total points
ID: 34907923
important notes:
1) avoid using "....Select" and "Selection..." in your code, it will always perform faster
2) Copy and Paste Values is "overrated"... you can just say value = value
3) if the content of A10 is not a valid column name, your code will blow up on your face as there's no validation for it... we can make one though  if you want...
Sub Macro2()
dim strColumn as string
    strColumn = Range("A10").Value
    Columns(strColumn & ":" & strColumn).Value =     Columns(strColumn & ":" & strColumn).Value
End Sub

Open in new window

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 34911375
Thanks, perfect
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question