Hello All,
I wrote Python code to write data to an Excel worksheet1, and also add 5 status types to worksheet2 to be used to make a dropdown list for one column in worksheet1. Could someone help me with the code to do this in Python? I recorded the macro >>
I have tried a few things (like below), but am stumped and can't find much documentation out there. I need to declare the name of the 5 cells on worksheet2 as 'ValidStatus' and get column I on worksheet1 to be a list with ValidStatus as the choices.
Any help would be greatly appreciated. And, if anyone could refer me to some good documentation on Python and Excel, well that would be great!
Thanks,
jenn
I wrote Python code to write data to an Excel worksheet1, and also add 5 status types to worksheet2 to be used to make a dropdown list for one column in worksheet1. Could someone help me with the code to do this in Python? I recorded the macro >>
Code:
Sub Macro2() ' ' Macro2 Macro ' ' Sheets("Sheet2").Select Range("A1:A5").Select Range("A5").Activate ActiveWorkbook.Names.Add Name:="ValidStatus", RefersToR1C1:= _ "=Sheet2!R1C1:R5C1" Sheets("Sheet1").Select Columns("I:I").Select With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="=ValidStatus" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With End Sub
I have tried a few things (like below), but am stumped and can't find much documentation out there. I need to declare the name of the 5 cells on worksheet2 as 'ValidStatus' and get column I on worksheet1 to be a list with ValidStatus as the choices.
Code:
ws1 = wb.Worksheets(1) ws2 = wb.Worksheets(2) ws2.Cells(1,1).Value = "GREEN" ws2.Cells(2,1).Value = "YELLOW" ws2.Cells(3,1).Value = "RED" ws2.Cells(4,1).Value = "WHITE" ws2.Cells(5,1).Value = "NOT SURE" ws1.Columns("I").Validation.Add(Type = "xlValidateList", xlValidAlertStop, xlBetween, "=ValidStatus")
Thanks,
jenn
Comment