Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Using Excel's MODE function

Use Excel's MODE function to display the most common value present in a particular range of cells.

The Mode function looks like this:

=MODE(cell range)

As an example, if 35 is the most commonly recurring number in a particular cell range, then the function will display 35.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.