LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code snippet works but is a bit 'clumbsy'


Excel 2010.

This snippet of code is from a much larger piece of code.
Range( C1:C26) are the letters of the alphabet.
When I run this snippet , CName asks for a letter. When a letter is entered it is assigned to Range("G1") and used to do stuff within the rest of the code, and that works very well.

I want this snippet to look at Range("C1:C26"), find that G1 value and shade the cell one column to the right, in Column D. It does that okay but the rub comes whereas it also shades the entire Range("C1:C26").

So I have added a simple procedure to clear the shading of Range("C1:C26") just below the line "CName = vbNullString".

'gotta be a better way to get all this done without doing so many SELECTIONS.

Option Explicit
Option Compare Text

Sub TestAtoZ()
Dim i As Integer
Dim c As Range
Dim CName As String

CName = InputBox(" Enter a duplicated letter from the" _
& vbCr & " last Capital name in column M." _
& vbCr & " If there is no duplicate in the" _
& vbCr & " Capital name, enter the first letter" _
& vbCr & " of the Capital name, B for Boise.", "State Letter")
Range("G1") = CName
Range("B1:B26").Select 'Values are A to Z & each appear only once
For Each c In Selection
If c.Value = Range("G1").Value Then c.Offset(0, 1).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
Next
CName = vbNullString
Range("B1:B26").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("G2").Select
End Sub

Thanks for any help.
Regards,Howard
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Snippet - Activate VBE window Tim Childs[_5_] Excel Programming 4 November 10th 10 08:13 PM
Want to modify this VBA code snippet joel Excel Programming 1 April 8th 09 08:46 PM
Want to modify this VBA code snippet Sam Commar Excel Programming 1 April 5th 09 01:50 PM
Problem in WITH/END WITH code snippet [email protected] Excel Programming 2 January 21st 06 02:59 PM
Code snippet storage Ken McLennan[_3_] Excel Programming 9 August 20th 04 03:25 PM


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"