I have a program that creates a userform, but it cannot complete the initialization. The initializer calls the sub below, supplying the relevant worksheet, category header, and combobox tag for the form. So far, it will find the header of interest on the worksheet. I want it to load all the cell data in the target header column into the form's combobox. The sub, however, has an issue with the line highlighted in red. I think it has to do with the way the combobox tag is referenced in the line, but I don't know how to fix it.
My file has 8 sheets with identical linked drop-down boxes at the top. Sheet1 has a graph that needs to be sorted from top to bottom each time a drop-down box from any of the sheets is adjusted. Using tips from this site, my macro moves to Sheet1, sorts, and then returns to whichever sheet I start at.
This works if the first drop-down box I adjust is from Sheet1. If the first drop-down box I adjust is from any other sheet I get "Run-time error '1004': Sort Method of Range Class Failed." Basically I get an error unless I use a Sheet1 drop-down box first. After using a Sheet1 drop-down box, all sheets work without error. How can I fix this error? Below is my macro................
I have just started VBA for the first time in Excel 2007. I have spent 2-3 hours trying to write text to a cell and I do not understand why it is not working. I have reduced the operation to the simplest form that I can find, now using the following
In applications I make in Excel I often make use of ComboBoxes to select a unique value.
Prior to Excel-2007 this was a complicated and time consuming loop construction that had problems with larger files. So I was happy to find the “Remove Duplicates” function in Excel-2007 and tried to use that.
- Select column of data. (In my example column F) - Copy to other sheet (DROP LISTS) - Apply Remove Duplicates function. - Sort alphabetically. - Establish length of list. - Set that range as Row Source of the ComboBox.
I have a log that I use to keep track of my hours where the days hours and charge numbers get summed and moved to a new sheet via a command button. One of the categories is week ending date. I want the week ending date cells to merge if they match and cannot get the range I want to highlight. I can move the data, find and define the first and last cells in the range, but can't get the range.select command to work. I think it is just a syntax error, as I am new to VBA.
I can open a Locals window and watch it assign values to myFirstCell and myLastCell of "$A$36" and "$A$44" respectively, but I get an error on either the set range= or range.select lines.
My code is as follows:
Private Sub Post_Hours_To_Log_Click() 'Posts the day's hours to the hours tracker.
Dim myFirstCell, myLastCell As Variant
Dim myRange As Variant
***Removed N/A code that goes to another sheet and decides which data to copy*** Application.Goto reference:=Worksheets("Hours Log").Range("A2"), _ Scroll:=False
Round Result Used As Vlookup Lookup_value Does Work For 6% in attached spreadsheet. I am an experienced user of Excel and have never come across something I could not solve before but this has stumped me. The issue is now sorted using different formulas but I do not know why the attached has #N/A errors in the Yellow highlighted cells.
I'm building a UserForm that has several TextBoxes to gather basic project information to fill in the header of a report. The first TextBox is the Job #... I'm trying to implement code for an "Auto Fill" button (based on working VBA code from another workbook) that will fill the other TextBoxes in the UserForm... The working VBA code from the other workbook does "Auto Fill" for Worksheet Ranges, not UserForm TextBoxes. How should I reference the UserForm Textboxes in the code to specify their value?
Workbooks("Template Generator.xls").Forms("ProjectInfo").Activate If TextBox("InptJobNum").Text = "" Then MsgBox "Please Insert Job Number" TextBox("InptJobNum").Select Exit Sub Else Jnum = TextBox("InptJobNum") 'Specify Job Number Workbooks("Job Log.xls").Sheets("Job Log").Activate End If If WorksheetFunction. CountIf(Range("A2:A1000"), Jnum) = 0 Then Workbooks("Template Generator.xls").Forms("ProjectInfo").Activate MsgBox "Invalid Job Number, or cannot be located... Please correct and try again" TextBox("InptJobNum").Select Exit Sub End If
Is there a way i can use a userform Textbox labeled jobNum1 in vba code with a counter "ctr" something like jobNum(ctr) = 5. I basically have multiple jobNum textboxes labeled jobNum1, jobNum2, jobNum3.....etc and would like to repeat the code for each counter until reaching 5. Take the following sub:
I have a userform that has a lot of textboxes that are formatted as date fields. Some of them have a default value and are locked=true, enabled=false. For those ones I have a checkbox next to them so the user can unlock and enable the textbox if they so desired.
Well the checkboxes and textboxes have a similar naming scheme, but are not numeric (they are not CheckBox1, CheckBox2, etc). As an example they one grouping is Cust1RelExpUnlock (this is the checkbox) and Cust1RelExpDateBox (this is the textbox). The difference in their name is the last portion (Unlock or DateBox).
Now when the checkbox is selected the code I want looks something like this:
Code: Private Sub Cust1RelExpUnlock_Click()UnlockDateBox Cust1RelExpUnlockEnd Sub
Where UnlockDateBox is the function I'm having difficulty with and is supposed to be generic enough to work on any grouping assuming my naming scheme is consistent.
Using a combination of the Left() and Len() functions I can get the unique aspects of the name. Then concatenate it with "DateBox" as required. However I'm getting type mismatch errors, or object required erros. I tried various combinations of Dim _____ As Object, As Control, As Textbox... with no success.
I'm getting the correct name as a string, how do I make it work so I can reference the textbox.enabled/.locked?
Code: Private Sub UnlockDateBox(Ck) Dim CkDate As Control 'Tried control, textbox, object Set CkDate = ProjectInputForm.MultiPage1.Object ' tried just using ProjectInputForm, and Object Dim CkName As String
I've have a combobox on a userform which should refer to a cell on a worksheet directly. E.g. The dropdown list that feeds to box is on Sheet2 range C1:C6 Whatever is selected should be copied to Sheet1 cell B18.
Now, if I populate cell B18 manually, it will pick it up, but if I then change the combobox selection, cell B18 either doesn't change or goes blank.?
I have a userform in wb "A" that I key data into. When I hit the 'submit' button I need the data to go to wb "b", ws "data" and go to cells in columns "CA-CK". All that I can do, when the data goes to wb "b" it need to load to the row that has the same date as the date I enter in textbox1 on the userform. The date column in wb "b" is column BX.
I have a userform with fields (TextBoxes) Num1, Num2, Num3, Num5 and Num5
I also have an array which i have looped through and seeded with five values.
Now when I try and loop again and pass the values from the array to each of the textboxes I cant remember the syntax to reference the textbox using the loop variable - Num(var). I've experimented with the & symbol but it escapes me at the moment !
I have a fairly big excel spreadsheet with about 2 userforms at the moment. One Userform (the main one) has a multipage control with about 12 pages. Now here is the weird part. I open up the excel document and this main user form loads up simply with this code
Sub Auto_Open() Load Userform1 Userform1.show End Sub
This works fine the form loads. Now on this form there is a multipage control with about 12 pages as mentioned above. Now everything works the way I want it to eg the text boxes, combo boxes, command buttons etc all work and link with the worksheets fine just the way they should...But if I reference or try to use a couple of the controls in any way excel crashes. It doesn't give any errors or anything it just crashes and then I get a prompt saying do you want to send the error report blah blah. I have narrowed it down to 3 command buttons and 1 combo box so far that this happens on. If I do the most basic of commands on any of these controls such as something as simple as msgbox problemcombobox.visible...
This piece of code runs perfectly on its own but when called at the end of another code it fails and I haven't a clue why. The reference wsTmp is dim'd globally and defined in the main component where it is simply - worksheets("somename")
Run-time error '1004':
The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank.
I have workbooks in which summary tables are generated by lookup formulas. Tables are on different sheets but all use the same lookup value by referring to a cell on the 'master' sheet. The lookup value appears in cells on all sheets, by reference to the master sheet (e.g. [formula] = mastersheet!$B$2).
The master sheet contains the main summary table and is copied and detached for distribution, using a macro. For practical reasons, this is done in two stages, first copying the sheet within the workbook (to make minor alterations), then moving it to a new book to save and distribute.
This is where the problem arises. After the sheet has been detached, we find that if we now change the lookup value on the master sheet in the original file, the tables on that sheet will update normally, but the cells on other sheets remain frozen at the previous value and the tables on those sheets do not update.
The only way round the problem is by Shift + Ctrl + Alt + F9. (Maybe I should add that all my workbooks are always set to automatic calculation.)
The macro itself is not the cause of the problem; if we follow the same procedure manually, the result is the same. However, if we move the sheet in one step, eliminating the intermediate copying stage, the problem does not arise. But this is evading the problem, not solving it, and I would be reluctant to have to resort to this.
The original problem remains as stated, viz. failure of automatic calculation.
How do you create a reference number to be posted in a userform2 that is opened from an earlier userform1 where you have entered some initialisation data and generated a source reference number. ie set of data has reference X and there will be y items in that set want references in form X01 to Xy (y unlikely to exceed 20). Want to put references 'X01' into the userform2 and cycle through data entry in userform2 from source reference X01 to Xy. (I'm having problems with the transfer from 1 to 2!)
I have a sub that I need to call multiple times. I'm trying to figure out if there is a better way to do this rather than write out the call each time:
AYForm = "UserForm2.txtAYMonths" & i AYPForm = "UserForm2.txtAYPercent" & i SummerForm = "UserForm2.txtSummerMonths" & i SummerPForm = "UserForm2.txtSummerPercent" & i JobForm = "UserForm2.cboJobClass" & i NameForm = "UserForm2.txtName" & i
For i = 1 To 15 Call FormatAY((AYForm), (AYPForm), (SummerForm), (SummerPForm), (JobForm), (NameForm))
' Call FormatAY(UserForm2.txtAYMonths & i, UserForm2.txtAYPercent & i, UserForm2.txtSummerMonths & i, _ ' UserForm2.txtSummerPercent & i, UserForm2.cboJobClass & i, UserForm2.txtName & i) Next i
the sub FormatAY has six arguments; 5 textboxes and 1 combobox. Since the names of these items are the same except for a number (example UserForm2.cboJobClass1, UserForm2.cboJobClass2, UserForm2.cboJobClass3 etc...), I wanted to write a for loop and use a variable to represent the last number. Is this even possible? The couple of ways that I have tried this, I get either a member not found, or ByRef error.
Every new file I create is named with a sequential reference based on some criteria:
So, in my worksheet I have several columns with package names: LABK, LAVO, LACRâ€¦ and on the rows I have the file names.
I have this UserForm I created Search.JPG
Basically (despite I imagine itâ€™s not that simple), when I type the package name and the place as follows, for example
Package = LABK Place = SAO
After clicking on â€śGenerateâ€ť button, it should look for all file names containing LABK and SAO, verify what the last sequential number is (highest/MAX) and generate a new one in the text box below the button.So, if the last file name is LABK_(SAO005), itâ€™ll generate a new one as LABK_(SAO006).
I've been using a macro successfully for the last couple of years, but this morning when I went to use it, it decided to fail. I have a workbook which contains various spreadsheets. The macro that has failed performs the following tasks:
1. It copies a list of email addresss from an external workbook to a sheet in the current workbook (still works) 2. It copies the referral sheet I want to send to a new file, and saves it with an appropriate filename to an appropriate folder (still works) 3. The macro then creates an email with a standard subject line, attaches the new worksheet and emails it to each of the addresses as above (broken)
The error message is from Microsoft Visual Basic. "Run-time error '1004': Mail system failure. Check your mail installation."
I'm guessing there is a setting somewhere in Excel that has changed as part of an update.
I've been through a number of the options in the developer menu to remove any obvious restrictions (& reopened excel afterwards), but so far it hasn't resolved the problem.
For what it's worth, here is the macro code.
With Application .EnableEvents = False .ScreenUpdating = False End With Run "PullInSheet1" Dim oldbook As String
In case you're wondering about the pullinsheet code, I'll add it below - but I probably grabbed it from this forum a couple of years ago (like some of the above) & just made some changes.
Code: Sub PullInSheet1() Dim AreaAddress As String '''''' Sheet11.UsedRange.Clear Dim ClRange As String ClRange = "= 'L:ADMINEMPLOY SERVICES" _
There are a couple of things I've wanted to do to improve the macro, but I couldn't justify the need to spend time working it out (since writing spreadsheets isn't really my job). Since it's broken at the moment, I can...
1. I'd like to create a subject line that reflects the name of the person being referred. For some reason though, anything other than text in the cell reference caused an error for me. eg, I tried using concatenate to create my subject line, but it didn't work.
2. I'd like the copied sheet to contain all of the formatting of the original sheet. Presumably there is a paste option that will do this and I just picked the wrong one.
The mailsystem we use is Groupwise 8. I couldn't find any settings in that program that have been changed, or that I could change.
I should change the extension from xls to xlsx in the code since I'm using Excel 2010 (but changing it doesn't fix the problem).
What I would like to do is create a userform where I can input a case reference number and click a command button which searches the CSV/TXT file for any notes for the specific reference number and then returns all notes (seperated by a blank line) in the textbox within the userform in the posted/saved format.
I can find lots about importing to excel but nothing about importing data to userforms.
CSV file added for format. The userform contains two text boxes, one blank for import and one for completing the case reference number (format on CSV file. Line item 1).
i.e. if I searched by SL-001-0155648 I would get the below (It's not code but I thought the best way of showing what I mean):
My workbook holds a month template and sheets for each month. I work on modifications in the template ,but would then like to update all the monthly worksheets. I recorded a macro to show me how to start programming the vb sub, but get a runtime failure 'error 1004 Select method of range class failed' when trying to select the column to copy,
I have encountered some difficulty in modifying a macro I wrote into what I need. I created a macro that searches a column (Column C) for a cell value of, "stop", and then it copies everything above that cell and pastes it onto another sheet. In the sample data set that I was using, "stop" first occurred in cell C541, so the macro copies C1:C540 and pastes it onto another sheet. The problem is that the macro created an absolute reference to C540. What I desire is for the macro to use the 'Find' function to locate the first occurrence of, "stop", offset one cell above that cell, and then reference the active cell (which was positioned by these last two steps) in the range that should be copied. Basically, I'm hoping to have cells C1 through the active cell copied and then pasted onto another sheet.
A 'Days Attended' cell (N8) and a 'Days Absent' cell (O8). N8 needs to count the number of "Present" values there are on another worksheet. The other worksheet has dates across the top and names down the side.
When i use =COUNTIF("Attendance!C9:Z9", "Present"), and the next date comes along the formula changes to =COUNTIF("Attendance!D9:AA9", "Present")
ie. the reference moves a column across - the new date's absent or present is not counted. Using =COUNTIF(INDIRECT("Attendance!C9:Z9"), "Present"). is no good because when i add a new name i need the row reference to move down as a row is inserted. ie. both person's formulas count the same row. So, my question: I need the columns to stay the same - C:Z (leyway for future dates) and the rows to change as i insert or delete people from the system.