Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Conditional Formatting through VBA ODBC

Can anyone point me in the right direction with this Macro.

I'm trying to get some Conditional Formatting through VBA when I download
data fron an ODBC link.

As it stands, the Macro below (which I got from the Forum) colours the cells
correctly if the data is keyed / pasted into the Spreadsheet, but NOT after
an ODBC download.

Can anyone assist?



Private Sub Worksheet_Change(ByVal Target As Range)


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("C1:C50")) Is Nothing Then
With Target
Select Case UCase(.Value)
Case "A": .Interior.ColorIndex = 3
Case "B": .Interior.ColorIndex = 4
Case "C": .Interior.ColorIndex = 5
Case "D": .Interior.ColorIndex = 6
Case "E": .Interior.ColorIndex = 7
Case "F": .Interior.ColorIndex = 8
Case "G": .Interior.ColorIndex = 9
Case "H": .Interior.ColorIndex = 10
Case "I": .Interior.ColorIndex = 11
Case "J": .Interior.ColorIndex = 12
Case "K": .Interior.ColorIndex = 13

End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200805/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional Formatting through VBA ODBC

Not sure which event would work in your case, but the Worksheet_Change does
not appear to be the correct one. Maybe Worksheet_Activate? Or tag this
macro onto the tail end of your download code.

"Francois via OfficeKB.com" wrote:

Can anyone point me in the right direction with this Macro.

I'm trying to get some Conditional Formatting through VBA when I download
data fron an ODBC link.

As it stands, the Macro below (which I got from the Forum) colours the cells
correctly if the data is keyed / pasted into the Spreadsheet, but NOT after
an ODBC download.

Can anyone assist?



Private Sub Worksheet_Change(ByVal Target As Range)


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("C1:C50")) Is Nothing Then
With Target
Select Case UCase(.Value)
Case "A": .Interior.ColorIndex = 3
Case "B": .Interior.ColorIndex = 4
Case "C": .Interior.ColorIndex = 5
Case "D": .Interior.ColorIndex = 6
Case "E": .Interior.ColorIndex = 7
Case "F": .Interior.ColorIndex = 8
Case "G": .Interior.ColorIndex = 9
Case "H": .Interior.ColorIndex = 10
Case "I": .Interior.ColorIndex = 11
Case "J": .Interior.ColorIndex = 12
Case "K": .Interior.ColorIndex = 13

End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200805/1


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Conditional Formatting through VBA ODBC

JLGWhiz wrote:
Not sure which event would work in your case, but the Worksheet_Change does
not appear to be the correct one. Maybe Worksheet_Activate? Or tag this
macro onto the tail end of your download code.

Can anyone point me in the right direction with this Macro.

[quoted text clipped - 34 lines]
Application.EnableEvents = True
End Sub



I decided to try a different method:-

' Refresh ODBC
Range("D8").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Range("D8").Select



For I = 1 To 100

With ActiveSheet.Cells(I, 4) 'COL 4 = COL D

If .Value = "123" Then
.Interior.ColorIndex = 3

ElseIf .Value = "456" Then
.Interior.ColorIndex = 4

ElseIf .Value = "789" Then
.Interior.ColorIndex = 5

ElseIf .Value = "abc" Then
.Interior.ColorIndex = 6

'etc


End If
End With
Next


I don't suggest it's smart, only that it works.

Thanks for your reply, and to others on my wrongly posted thread

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200805/1

Reply
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
How can I convert conditional formatting into explicit formatting? Patrick Harris Excel Discussion (Misc queries) 0 April 9th 09 12:00 AM
Formatting cells in a column with conditional formatting? shamor Excel Discussion (Misc queries) 8 May 19th 08 10:11 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


All times are GMT +1. The time now is 07:01 PM.

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

About Us

"It's about Microsoft Excel"