This is the code that I created to try to shade columns, representing months, within each row based on the combination of the leadtime and a 2-digit month code.
The objective:
When looking at the 2-digit code for each row, start shading the month (corresponding column "1" for Jan, "2" for Feb. etc.) designated and stop shading based on the lead time shown in days. For example, if the 2-digit code is "32" representing "December" and the lead time if "100" for days, start shading at the 12th column through the 15th columns (4 columns over). The 4 columns results from the 100 days lead time which fall within the fourth month (100 days / 30 days = 3.33 months)
The second number of the two-digit month code designates the month with a couple of exceptions. For example, the 2-digit code of "24" having the second number of "4" represents "April". This format follows until the months of November or December which need the full 2-digit month code of "11" or "31" for Nov. and "12" or "32" for Dec.
Problem:
The below code works until the 2-digit code EQUATES TO July, August, September, October, November or December when the second digit of the 2-digit month code is "7", "8", "9", "0" or the full 2-digit code is "11", "31", "12", "32" for November and December. When the 2-digit code falls within these parametersm, it results in no coding.
I have tried so many things to get this to work with no improvement. I'm in a HUGE BIND, any ASSISTANCE is APPRECIATED
Code Below:
Case "1" through "6" have the same code therfore you don't need to review when attempting to follow the code.
Sub ColorShade()
Dim myRng As Range, myRow As Integer, myCol As Integer
Dim myDuration As Single, myLeadDate As Single, rtCol As Integer
Dim offSetCell As Integer, myRightVal As Integer
Sheets("sheet1".Select
Sheets("sheet1".Range("ba3".Select
myRow = ActiveCell.Row
myCol = ActiveCell.Column
offSetCell = 1
Set myRng = ActiveSheet.Cells(myRow, myCol)
Do While myRng <> ""
myLeadDate = ActiveSheet.Cells(myRow, myCol + 1)
If myLeadDate Mod 30 = 0 Then
myDuration = (myLeadDate \ 30)
Else
myDuration = (myLeadDate \ 30) + 1
End If
myRightVal = Right(myRng.Value, 1)
Select Case myRightVal
Case "1"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "2"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "3"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "4"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "5"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "6"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Select
myRow = myRow + 1
Set myRng = ActiveSheet.Cells(myRow, myCol)
Loop
End Sub
I APPRECIATE ANY ASSISTANCE,
Dyana
The objective:
When looking at the 2-digit code for each row, start shading the month (corresponding column "1" for Jan, "2" for Feb. etc.) designated and stop shading based on the lead time shown in days. For example, if the 2-digit code is "32" representing "December" and the lead time if "100" for days, start shading at the 12th column through the 15th columns (4 columns over). The 4 columns results from the 100 days lead time which fall within the fourth month (100 days / 30 days = 3.33 months)
The second number of the two-digit month code designates the month with a couple of exceptions. For example, the 2-digit code of "24" having the second number of "4" represents "April". This format follows until the months of November or December which need the full 2-digit month code of "11" or "31" for Nov. and "12" or "32" for Dec.
Problem:
The below code works until the 2-digit code EQUATES TO July, August, September, October, November or December when the second digit of the 2-digit month code is "7", "8", "9", "0" or the full 2-digit code is "11", "31", "12", "32" for November and December. When the 2-digit code falls within these parametersm, it results in no coding.
I have tried so many things to get this to work with no improvement. I'm in a HUGE BIND, any ASSISTANCE is APPRECIATED
Code Below:
Case "1" through "6" have the same code therfore you don't need to review when attempting to follow the code.
Sub ColorShade()
Dim myRng As Range, myRow As Integer, myCol As Integer
Dim myDuration As Single, myLeadDate As Single, rtCol As Integer
Dim offSetCell As Integer, myRightVal As Integer
Sheets("sheet1".Select
Sheets("sheet1".Range("ba3".Select
myRow = ActiveCell.Row
myCol = ActiveCell.Column
offSetCell = 1
Set myRng = ActiveSheet.Cells(myRow, myCol)
Do While myRng <> ""
myLeadDate = ActiveSheet.Cells(myRow, myCol + 1)
If myLeadDate Mod 30 = 0 Then
myDuration = (myLeadDate \ 30)
Else
myDuration = (myLeadDate \ 30) + 1
End If
myRightVal = Right(myRng.Value, 1)
Select Case myRightVal
Case "1"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "2"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "3"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "4"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "5"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "6"
ActiveSheet.Cells(myRow, (myCol + myRightVal + offSetCell)).Select
rtCol = ActiveCell.Column
ActiveSheet.Range(Cells(myRow, rtCol), Cells(myRow, rtCol + myDuration - 1)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Select
myRow = myRow + 1
Set myRng = ActiveSheet.Cells(myRow, myCol)
Loop
End Sub
I APPRECIATE ANY ASSISTANCE,
Dyana