98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA
Excel VBA
Resolved · High Priority · Version 2003
John has attended:
Excel VBA Intro Intermediate course
Excel VBA
I have a spreadsheet with several columns with a header called'Result' where data is calculated (using formula)
How to copy and paste special - values data in the same columns? The code should be able to run for all columns with a header.
RE: Excel VBA
Hi John,
Thank you for your question.
Assuming your worksheet name is Sheet1 and the header row is on row 1, you can try the following code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub PasteValue()
Dim Columns As Byte
Dim Counter As Byte
Sheets("Sheet1").Select 'Make sure you are on the correct sheet
Range("A1").Select 'Start of header row
Columns = Range(Selection, Selection.End(xlToRight)).Columns.Count 'Find no. of Heading labels
For Counter = 1 To Columns
If ActiveCell.Value = "Results" Then
ActiveCell.Offset(1, 0).Activate 'Select 1st result formula
Range(Selection, Selection.End(xlDown)).Copy 'highlight till the last result formula
Selection.PasteSpecial Paste:=xlPasteValues
Selection.End(xlUp).Select 'Return to Header row
End If
ActiveCell.Offset(0, 1).Activate 'Try next header
Next Counter
Application.CutCopyMode = False
Range("A1").Select 'Return to the beginning
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
See if that helps.
Katie Woo
Microsoft Certified Trainer
Tue 3 Feb 2009: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Line breaks in a cellYou can control the line breaks for multiple-line headings or labels in your Microsoft Excel worksheet, just like you do in Microsoft Word. Here's how to do it. |