|
Highlight Every Other Row in a Selection in Excel - Table Formatting
This free Excel macro will highlight every other row in a selection of cells with a color that is specified within the macro. To use this macro, you must first select a range of cells or a table in Excel and then run the macro. From there, the first row and then every other row will have a background color. This allows you to easily navigate large tables and more clearly present information in Excel.
To change the color that the rows will change to, just change the number at the end of this line within the macro:
Selection.Rows(r).Interior.ColorIndex = 37
The number at the end of the row above is a color index number for Excel.
Where to install the macro: Module
Excel Macro to Highlight Every Other Row in a Selection in Excel - Table Formatting
Sub Highlight_Every_Other_Row()
'This macro highlights every other row within a selection of rows - you select the table/rows you want formatted
Dim r As Integer
For r = 1 To Selection.Rows.Count
If r Mod 2 = 1 Then
Selection.Rows(r).Interior.ColorIndex = 37
End If
Next
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hi ,
Since you were all such a great help for me yesterday I need your expertise today..
I am still building my World Cup Spreadsheet and I need to get these two things accomplished today
1. I want to place a format to my group table so as that the team with the most points and goal difference is on top, but I need the spreadsheet to do automatically based on the results of the groups matches.
2. In the matches pairing I want to put an instruction so as that the winning team is in blue the loosing team in green and if its a draw red font.
I have a number in cell J10 and need to highlight the closest number to it from the following cells:N10, R10, V10, Z10, AD10, AH10, AL10, AP10.
I have found help from sites that show things in columns but I need to know how to do it in rows instead.
I have looked for a couple of hours and am very frustrated. Thanks for your help!
I have a sheet with a column of names and an adjacent array with those names distributed in different places. I want to select a name in the column causing all the cells in the array containing the name to be highlighted.
The best I have been able to do is to a conditional format in the array with "cell value" "is equal to" =VLOOKUP("x",I1:J49,2), then type an "x" next to the name in column I in the I1:J49 array, returning the name in column J.
I don't want to type next to the name. I want to click on the name and have it highlighted in the array.
Any ideas?
Hello!
I have a VBA module that performs several things when a command button is clicked. One of the last things it does is paste values, so when the module is comeplete the pasted area is still copied to the clipboard; in other words, it is outlined in pulsating dashes.
What can i add to the end of the code to un-copy this selection?
Thank you!!!
Hello!
I have a VBA module that performs several things when a command button is clicked. One of the last things it does is paste values, so when the module is comeplete the pasted area is still copied to the clipboard; in other words, it is outlined in pulsating dashes.
What can i add to the end of the code to un-copy this selection?
Thank you!!!
Hiya,
I've written a short macro to paste a range from an excel sheet to a word document. The desired result is that the range will correctly retain the excel formatting and span x pages rather than meandering off the end of the document.
Here's my code so far...
Code:
Private Sub Receipt_Click()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
Set wdDoc = wdApp.Documents.Open _
(Filename:="\\Staff-serv1\cciadmin\STUDENT JOURNEY\WIP\Static Templates\2.doc")
wdApp.Visible = True
' This is Word VBA code, not Excel code
ActiveSheet.Range("C8").Value = Date
ActiveSheet.Range("C8").NumberFormat = "dd\/mm\/yy"
Sheets("Receipt").Activate
ThisValue = ActiveSheet.Range("D10").Value
ActiveSheet.Range("A1" & ":C" & ThisValue).Copy
wdApp.Selection.PasteSpecial
Sheets("Main").Activate
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub
It's falling down as it doesn't retain the excel formatting, it reverts to Times New Roman word defaults and assumes word table styles. It does span pages correctly however.
I've experimented with several PasteSpecial options, but nothing seems to have the desired effect.
Any help gratefully accepted!
Can someone help me with a VB code that will find the last active cell in column "A" and then highlight accross in that particular row A:S (But only highlight the last active row)
Light gray (25%)
Thanks,
Hi, after sorting information that I show in a listbox I would like to
highlight the first item showing up at top of the listbox(right now I
get by default a dotted line under the first item)
Thank's ahead for any hint!
My code:
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item
Sub slist()
i = 1
Set NoDupes = New Collection
For Each ws In Worksheets
NoDupes.Add (Worksheets(i).Name)
i = i + 1
Next ws
' Sort the collection
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) > NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo =j
NoDupes.Add Swap2, befo =i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i
' Add the sorted items to a ListBox
Userform1.ListBox1.Clear
For Each Item In NoDupes
Userform1.ListBox1.AddItem Item
Next Item
Userform1.Show
Set NoDupes = New Collection
End Sub
Hi,
I have a excel file which is used for the data entry purpose. I need a solution for the record selects to be highlighted which will be known that the entry is completed. When i click the down arrow key the particular cell is to be highlighted. Is it possible??
Thanks in advance
ravi
|
|