carlomscalisi
New Member
- Joined
- Jun 20, 2016
- Messages
- 16
Please see the attached photo of the spreadsheet.
Here's what I'd like to happen:
When I click on the button "Add Row," I would like it to create a new row in row 17 between columns A and V (A17:V17). I need columns A-C (A17:C17) to be Merged and the text Left Aligned, and then the text in the rest of the columns D-V (D17:V17) to be Centered. I would like the text to be the same font and size, however I would like the text in V17 to be Bold. I would also like the format of cell D17 to be Text, so that "2/3" won't default to "3-Feb". I seem to have accomplished all of this so far with the code that I have:
Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("A17").Select
ActiveCell.EntireRow.Insert Shift:=x1Down
Range("A17:C17").Merge
Range("E17:V17").Orientation = xlHorizontal
Range("D17").NumberFormat = "@"
Range("O17:P17").Font.Size = "10"
Range("A17:V17").Interior.ColorIndex = 0
Sheets("Sheet1").Range("A17:V17").Select
Selection.Borders.Weight = xlThin
Selection.RowHeight = 12.75
Selection.Font.Bold = False
Range("A17:A17").HorizontalAlignment = xlLeft
Range("V17").Font.Bold = True
I am fully aware that, although this code works, it's probably not the best. However my problem is with the next thing that I would like to accomplish when hitting the Button:
I would like there to be If else with Conditional Formatting applied to A17:U17 wherein, if the text is N, the cell color will change to Red, and if it's anything else, the cell will have no fill. I have somehow pieced together the following code that I've applied directly below the above code:
Sheets("Sheet1").Range("A17:V17").Select
For Control = 1 To 1
Application.Wait (Now + TimeValue("0:00:1"))
For i = 1 To 100
For col = 5 To 21
If Cells(i, col).Value = "N" Then
Cells(i, col).Interior.ColorIndex = 3
Else
If Cells(i, col).Value = "Y" Then
Cells(i, col).Interior.ColorIndex = 0
End If
End If
Next
Next
Next
End Sub
Once again, I have no idea what some of these codes even do or mean, but I've copied and pasted from websites and tried to piece something together. What I've found is that it actually does change the cell color to Red if the text is "N", HOWEVER, it only changes the color if I hit the Button again and add another row.
So what I'd like to do, obviously, is to have the cell color change to Red automatically if "N" is entered in the cell. I don't know if there's a way to make it happen immediately, or if I need to do an Application.OnKey thing or something else.
I would GREATLY appreciate your help.
Thank you!
Here's what I'd like to happen:
When I click on the button "Add Row," I would like it to create a new row in row 17 between columns A and V (A17:V17). I need columns A-C (A17:C17) to be Merged and the text Left Aligned, and then the text in the rest of the columns D-V (D17:V17) to be Centered. I would like the text to be the same font and size, however I would like the text in V17 to be Bold. I would also like the format of cell D17 to be Text, so that "2/3" won't default to "3-Feb". I seem to have accomplished all of this so far with the code that I have:
Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("A17").Select
ActiveCell.EntireRow.Insert Shift:=x1Down
Range("A17:C17").Merge
Range("E17:V17").Orientation = xlHorizontal
Range("D17").NumberFormat = "@"
Range("O17:P17").Font.Size = "10"
Range("A17:V17").Interior.ColorIndex = 0
Sheets("Sheet1").Range("A17:V17").Select
Selection.Borders.Weight = xlThin
Selection.RowHeight = 12.75
Selection.Font.Bold = False
Range("A17:A17").HorizontalAlignment = xlLeft
Range("V17").Font.Bold = True
I am fully aware that, although this code works, it's probably not the best. However my problem is with the next thing that I would like to accomplish when hitting the Button:
I would like there to be If else with Conditional Formatting applied to A17:U17 wherein, if the text is N, the cell color will change to Red, and if it's anything else, the cell will have no fill. I have somehow pieced together the following code that I've applied directly below the above code:
Sheets("Sheet1").Range("A17:V17").Select
For Control = 1 To 1
Application.Wait (Now + TimeValue("0:00:1"))
For i = 1 To 100
For col = 5 To 21
If Cells(i, col).Value = "N" Then
Cells(i, col).Interior.ColorIndex = 3
Else
If Cells(i, col).Value = "Y" Then
Cells(i, col).Interior.ColorIndex = 0
End If
End If
Next
Next
Next
End Sub
Once again, I have no idea what some of these codes even do or mean, but I've copied and pasted from websites and tried to piece something together. What I've found is that it actually does change the cell color to Red if the text is "N", HOWEVER, it only changes the color if I hit the Button again and add another row.
So what I'd like to do, obviously, is to have the cell color change to Red automatically if "N" is entered in the cell. I don't know if there's a way to make it happen immediately, or if I need to do an Application.OnKey thing or something else.
I would GREATLY appreciate your help.
Thank you!