Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

How to set Cells Range as Variables

$
0
0

I want to set Cells range with Variable X and Y. Then I need ElseIf statements to have (y+1, x) values.

I tried it with Cells(y, x) and Range(y, x), but still got a 1004 run-time error

Private Sub LightL1_Click()

  G = RGB(0, 255, 0)
  O = RGB(255, 153, 0)
  R = RGB(255, 0, 0)
  P = RGB(204, 0, 204)

  Clr = G     'Color pick

  x = 25      'column
  y = 21      'row

  If Me.Bay1.Value = "36" Then
         Cells(y, x).Interior.Color = Clr

      ElseIf Me.Bay1.Value = "35" Then
        Cells(y + 1, x).Interior.Color = Clr
      ElseIf Me.Bay1.Value = "34" Then
        Cells(y + 2, x).Interior.Color = Clr
      ElseIf Me.Bay1.Value = "33" Then
        Cells(y + 3, x).Interior.Color = Clr
      'Etc...
  End If
 End Sub

What am I doing wrong?


Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>