excel-vba

Automatically adapt listbox column width

独自空忆成欢 提交于 2020-02-25 00:38:42
问题 I programmatically add elements from a database to a multicolumn listbox using this code : Do While (Not rs.EOF) ExistingSheetsListBox.AddItem ExistingSheetsListBox.List(i, 0) = rs.Fields(0) ExistingSheetsListBox.List(i, 1) = rs.Fields(1) ExistingSheetsListBox.List(i, 2) = rs.Fields(2) ExistingSheetsListBox.List(i, 3) = rs.Fields(3) ExistingSheetsListBox.List(i, 4) = rs.Fields(4) i = i + 1 rs.MoveNext Loop The insertion in the listbox works fine, but the column width is not always adapted to

Assigning a variable directly from a userform

时光总嘲笑我的痴心妄想 提交于 2020-02-24 14:54:29
问题 I am trying to add some code to have a userform pop up which allows the end user to input their login/password for s specific website. This code Passing variable from Form to Module in VBA got me closer to my goal but I am not sure how to make it work the way I need to. Here is the code for my userform. Private Sub CommandButton1_Click() UPass = UserForm1.UserID Unload UserForm1 End Sub Private Sub CommandButton1_Click() UID = UserForm1.WavePassword Unload UserForm1 End Sub And I am using the

Distributing macro as an Add-In to other users

寵の児 提交于 2020-02-24 11:17:47
问题 I am looking for some tips how to resolve a problem with distributing macro to other users in my company. I’ve created a specific workbook which holds a bunch of various types of data such as dates, strings and numbers. Each of the users have to manage the same types of data, so we use this workbook as a template. Data is stored in a columns to which I’ve applied a conditional formatting and data validation to prevent users from inserting wrong values. This Workbook contains few Worksheets

Distributing macro as an Add-In to other users

岁酱吖の 提交于 2020-02-24 11:17:07
问题 I am looking for some tips how to resolve a problem with distributing macro to other users in my company. I’ve created a specific workbook which holds a bunch of various types of data such as dates, strings and numbers. Each of the users have to manage the same types of data, so we use this workbook as a template. Data is stored in a columns to which I’ve applied a conditional formatting and data validation to prevent users from inserting wrong values. This Workbook contains few Worksheets

Using object properties that aren't listed in Object Browser

六眼飞鱼酱① 提交于 2020-02-24 03:52:12
问题 I've been looking into the underlying structure of object properties and methods in VBA a bit more. I've just read that all properties and methods for each object is listed in the "Object Browser" in the developer box. The reason why I was prompted to look at this was that I used a method that wasn't listed in the Object Browser. I used: Sheets("Front face").Shapes("Drop Down 12").ControlFormat This allowed me to then use .List to change the Shape. However .ControlFormat isn't a property

Using object properties that aren't listed in Object Browser

a 夏天 提交于 2020-02-24 03:50:52
问题 I've been looking into the underlying structure of object properties and methods in VBA a bit more. I've just read that all properties and methods for each object is listed in the "Object Browser" in the developer box. The reason why I was prompted to look at this was that I used a method that wasn't listed in the Object Browser. I used: Sheets("Front face").Shapes("Drop Down 12").ControlFormat This allowed me to then use .List to change the Shape. However .ControlFormat isn't a property

Declare a Range relative to the Active Cell with VBA

爷,独闯天下 提交于 2020-02-23 09:26:44
问题 I need to declare a range object relative to the Active Cell. The problem is, the number of rows and columns I want to select is different each time the macro runs. For example, I have two variables: numRows and numCols . I want to select a range that has the ActiveCell in the upper-left corner hand has the cell with row ActiveCell.Row + NumRows and column ActiveCell.Column + NumCols in the bottom right (and then I intend to copy this data to an array to speed up my macro). Any suggestions on

Copy Excel Row if Cell is equal to a value

二次信任 提交于 2020-02-23 06:45:10
问题 I'm trying to copy and paste into a different workbook and spread that data over different sheets inside of the new workbook. I've got my VBA working, but it only works about 25% of the time. I continually get an error on "Run-time error '1004': Select method of Range class failed". Here is the script: Sub CopyData() Dim i As Range For Each i In Range("A1:A1000") Windows("data_1.xls").Activate Sheets("data_1").Activate If i.Value = 502 Then i.Select ActiveCell.Rows("1:1").EntireRow.Select

Copy tables to another worksheet

不羁的心 提交于 2020-02-23 04:20:06
问题 I have 2 tables, "Table1" and "Table2" in Worksheet(1). I would like to copy these tables to another worksheet(2) where the top left corner of Table1 is in the new worksheet at cell "A1" and the Top left corner cell of Table2 is in the new worksheet at cell "O1." Unless the ActiveCell is A1 in Sheet2, the tables won't copy and paste correctly. Am I not activating a sheet correctly? Sub CopyTables() Worksheets(2).Activate 'must be on ExHouStorm or Worksheet(1) Worksheets(1).ListObjects("Table1

Prevent autorun VBA code when opening a file

对着背影说爱祢 提交于 2020-02-23 03:48:15
问题 I'm facing a problem where I have written a User form where I have provided the application.visible = false in the workbook program sheet under on_open , now I'm able to run the program but I'm unable to open the workbook or the VBA program. Please help Thank you and Regards, Nagarjun B 回答1: To prevent autorun VBA code like Workbook_Open or Auto_Open click File › Open from the menu/ribbon, select your file and hold down the shift key when you click the Open button. For a detailed how-to also