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 >> -
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. -
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")
-
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
2 14584
Add-on -->
I finally (been looking/asking for months) ran across a method to get at the value of Excel constants for use in Pyhton scripting.
From http://aspn.activestate.com/ASPN/Coo.../Recipe/528870 ... To get the value of Excel Constants such as xlEdgeLeft (7) or xlThin (2)
type e.g. Debug.Print xlEdgeLeft in the Immediate window of the VBA editor and press enter. This helps for general knowledge, but still have not gotten my script to work...
I figured it out myself after many hours!!! Solution is: - 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"
-
-
wb.Names.Add("ValidStatus", "=vl!R1C1:R5C1")
-
ws1.Columns("I").Validation.Add(3, 1, 1, "=ValidStatus") ##Type = xlValidateList/3, AlertStyle = xlvalidAlertStop/1, Operator=xlBetween/1, Formula1="=ValidStatus"
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Markus |
last post by:
hi,
is there a way to set up an user, how only have restricted admin
rights on mysql server. this user only should be able to create DBs
(and drop them) and set grants on this new DB.
i think with the standard mysql-privileges this can't be done.
- when a user has the drop-priv he can drop ALL DBs in the server.
- when a user has grant...
|
by: Karen Sullivan |
last post by:
Hi, all. I'm fairly new to SQL, and I have been trying to create a table
from a text file. I have been looking at this for days, and can't find the
problem. I get a syntax error " Line 55: Incorrect syntax near
'DateUpdated'." Here is the query. Any suggestions would be appreciated,
as I am trying to learn and improve.
Use ACH
go
...
|
by: Manzoorul Hassan |
last post by:
I just Installed MySQL v4.1.14 and had created a Database (from a
script). But I would like to redo the Database portion of it but am not
able to drop the Database. If I do a "show database;" I still see the
database. But when I look in the data directory, it is not there. Below
is my attempt the create / drop the DB:
mysql> create database...
|
by: tom horner |
last post by:
Any ideas on why drop and create alias statements would take a long
time?
We recently went through an upgrade of our production database, which
included alter statements to table structures, create tables, drop
tables, and data inserts, deletes, and updates. Also, we dropped and
recreated all the alias's we had on the tables and views to...
|
by: Peter |
last post by:
Hello£¬everyone,
My program will collect a testing machine's data ,save the data and deal
with the data everyday. I want to use vb.net to create database, add and
delete tables or modify the records in the database.
Is it possible to create a SQL Server database using vb.net? I know I can
use vb.net and ADOX to create a Access database....
| |
by: Darren |
last post by:
I'm trying to create a file using drag and drop.
I want to be able to select a listview item drag it to the shell and create a file.
Each icon in the listview represents a blob in a database.
When I drop onto the shell I want a file created with a specified name containing the data from the database.
I've looked at the FileDrop format but it...
|
by: masri999 |
last post by:
I have a requirement in SQL 2005 in Development database
1. Schema dbo owns all objects (tables,views,SPs,UDFs etc) .
2. Only DBA's ( who are database owners ) can create, alter tables .
Developer's should not create or alter tables .
3. Developers can create/alter Stored Procedure/User Defined functions
in dbo schema and can execute...
|
by: Rahul B |
last post by:
Hi,
I have a user UCLDEV1 which is a part of staff and a
group(db2schemagrp1) to which i have not given any permissions.
The authorizations of that user are shown as
db2 =get authorizations
Administrative Authorizations for Current User
|
by: semaj.remle 'at' gmail |
last post by:
For files saved in source control, is it better to use code to DROP/
CREATE a procedure like this:
------------------------------------------------------------------
IF OBJECT_ID ('procName') IS NOT NULL
DROP PROC procName
GO
CREATE PROCEDURE procName
AS
BEGIN
--proc code
|
by: Eric Isaacs |
last post by:
Optional Create and Alter is nice because it fails, the original is
still in place as are the original permissions. Drop and create is
also valid in some cases if you want to clear/reset the permissions.
I use an approach which lets me choose which one I want to implement
on the fly. If I remove the first two dashes, the drop is disabled...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |