VBA help with Select Case or Case

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
626
Office Version
  1. 2016
Platform
  1. Windows
Hello Everyone not quite familiar with Select Case or case but know that is problem what I need done to reduce the VBA code below.

Basaclly what I like to do is use Select Case to go from Cell "AT" thru "AZ" with each case you will notice it checks Cells(y,"E") thru Cells(y,"W") skipping every 2 columns if true changes the Value from Cells(y,"F") thru Cells(y,"X") skipping every 2 columns. I have one for AM for each day of the week and one for PM for each day of the week below however like to reduce the Code. any Help is greatly appreciated.

VBA Code:
Sub convertRole()
Dim lr As Long
lr = Range("y1")
t = 2
'AM
'SUNDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AT") = True And Cells(y, "E") = Cells(1, x) Then
              Cells(y, "F") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'MONDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AU") = True And Cells(y, "H") = Cells(1, x) Then
              Cells(y, "I") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'TUESDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AV") = True And Cells(y, "K") = Cells(1, x) Then
              Cells(y, "l") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'WEDNESDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AW") = True And Cells(y, "N") = Cells(1, x) Then
              Cells(y, "O") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'THURSDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AX") = True And Cells(y, "Q") = Cells(1, x) Then
              Cells(y, "R") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'FRIDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AY") = True And Cells(y, "T") = Cells(1, x) Then
              Cells(y, "u") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'SATURDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AZ") = True And Cells(y, "W") = Cells(1, x) Then
              Cells(y, "X") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x

'PM
'SUNDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AT") = False And Cells(y, "E") = Cells(1, x) Then
              Cells(y, "F") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'MONDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AU") = False And Cells(y, "H") = Cells(1, x) Then
              Cells(y, "I") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'TUESDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AV") = False And Cells(y, "K") = Cells(1, x) Then
              Cells(y, "l") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'WEDNESDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AW") = False And Cells(y, "N") = Cells(1, x) Then
              Cells(y, "O") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'THURSDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AX") = False And Cells(y, "Q") = Cells(1, x) Then
              Cells(y, "R") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'FRIDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AY") = False And Cells(y, "T") = Cells(1, x) Then
              Cells(y, "u") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
'SATURDAY
For x = 32 To 45
    For y = 3 To lr
        If Cells(y, "AZ") = False And Cells(y, "W") = Cells(1, x) Then
              Cells(y, "X") = Cells(t, x)
              t = t + 1
        End If
    Next y
    t = 2
Next x
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I always like it when users just tell me their ultimate Goal.
Which I do not understand from reading your post.

And do not just show me a lot of code which may not work or is hard for me to understand.

You explain in specifics what your ultimate goal is, and I will try and write the code.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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