VBA cyklus for

Lima

New Member
Joined
Jun 23, 2010
Messages
5
Dear all,

I have problem with matching two columns - I need to color regions in czech republic, due tu value (1-8) in another column... I have some macro, but I don´t know, how to assign each (right) rows together...

could you please help?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
For Target.Address =  "$AA$5" To "$AA$68" '(values)
For X = "$X$5" To "$X$68" 'name of regions (shapes)
Select Case Target.Value
        Case Is = 1
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 2
                        
        Case Is = 2
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 3
            
        Case Is = 3
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 4
            
        Case Is = 4
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 5
        
        Case Is = 5
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 6
            
        Case Is = 6
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 7
            
         Case Is = 7
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 16
            
         Case Is = 8
            ActiveSheet.Shapes("X").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 25
                        
    End Select
Next X
Next Y
End Sub

This one is working, but I have to do it more than 50 times.. :-(
Private Sub Worksheet_Change(ByVal Target As Range)

Code:
If Target.Address = "$AA$26" Then
    Select Case Target.Value
        Case Is = 1
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 2
        Case Is = 2
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 3
        Case Is = 3
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 4
         Case Is = 4
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 5
        Case Is = 5
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 6
        Case Is = 6
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 7
        Case Is = 7
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 16
        Case Is = 8
            ActiveSheet.Shapes("Okres_CH").Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 25
      End Select
      
End If

End Sub


Thank you very very much!!!

Lima
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I think you need something like this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    For rowCtr = 5 To 68
    
    Select Case Range("$AA$" & rowCtr).Value
        Case Is = 1
            ActiveSheet.Shapes(Range("$X$" & rowCtr).Value).Select
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 2
                            
           '
           '
           '  do each case
           '
           '
           
        End Select
    Next rowCtr
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top