excel vba

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

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA

Excel VBA

resolvedResolved · 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 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:

Line breaks in a cell

You 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.

Click the cell where you want the label or heading to appear.
Type the first line of information.
Press ALT+ENTER.

View all Excel hints and tips


Server loaded in 0.09 secs.