I tested your spread sheet and when I click the button I go to sheet2 b2.
I am using MSOffice 2010
Posts by rabsofty
-
-
please post your spreadsheet!
-
change your calculation setting.
in the formula's tab change the Calculation Options to Automatic. -
I'm not sure what you are trying to do after you extract those words? Are you trying to extract other data to put into those columns?
However, if you simply just want to extract only those words in adjacent cells then(formulas to go into adjacent cells)
-
Code
=IF(ISERROR(FIND(".",A1,1)),A1 * 60,LEFT(A1,FIND(".",A1,1)-1) * 60 + MID(A1,FIND(".",A1,1)+1,3))
this is how I did it. (I'm sure there are many other ways to do it!)
check for the decimal, (ISERROR(FIND(".",A1,1)))
If no seconds, multiply A1 by 60
if seconds exist, find the decimal, multiply left of decimal by 60 and add right of decimalP.S.
36 mins and 17 secs = 1277 secs -
Re: Using Variable to call Index of Combo Box
-
Re: Userform with 16 comboboxes; "Out of memory"
I tried your code and do not get the memory error. Maybe providing your spreadsheet to this post might help determine the cause.
Here is one way to shorten your code.
<Code>
Dim y, x As Integer, obj As Object
'x = column & y= row based on O31
x = 21: y = Sheet2.Range("O31").value
For z = 0 To 15
Set obj = Me.Controls("ComboBox" & z + 1)
Sheet2.Cells(y, x+z).value = obj.text
Next z
</Code> -
Re: check boxes in userform
if its in a frame and you only want one, then user the option buttons instead!
-
Re: BeforeUpdate event triggering as soon as textbox is clicked, in addition to after
Jennster, trust me 1500 lines isn't that much.
can you simply export that userform to this forum for testing
-
Re: BeforeUpdate event triggering as soon as textbox is clicked, in addition to after
anytime you access or change your textbox, the event is triggered.
with a textbox's before,after, change,click event, it will always go to the event.
That means every time you type a character, the event gets triggered.to avoid the trigger event issue, simply check it elsewhere and not by a trigger event.
listboxes and comboboxes events are a little different
for example for a combo box change event change event can be checked but ignored easily with the followingprivate sub something_change()
if something.matchfound=false then exit sub
do stuff here if true
end subwith a combobox the event is triggered when it changes and if it does not match it does nothing.
a textbox is different in the fact it is not looking at one entry at a time, it looks at every character typed -
Re: Convert mmmm d yyyy to dd/mm/yyyy
If your computer has that date format then you can use.
(other computers can have different date formats defaulted on their computer)but to make sure it's always in the format you want then
where thedate is your date
-
Re: BeforeUpdate event triggering as soon as textbox is clicked, in addition to after
I used to have the same issue, my fix was to check the field when dialog closes check that field using the userform_queryclose event
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
put code here to check textbox field
End sub -
-
Re: using a common class module for cancel buttons across all userforms
I have readjusted my class so it can make use of all userform objects that I can communize
class module name = cFrmClk
Code
Display More'class cFrmClk - 2017\06\21 by Rickb Public WithEvents BtnGrp As MSForms.CommandButton Public WithEvents LstGrp As MSForms.ListBox Private Actuf Private Sub BtnGrp_Click() Set Actuf = BtnGrp.parent Select Case BtnGrp.Name Case "HelpBT" Call gethelp(ghix()) Case "CancelBT" Call rcanit Case "RefreshBT" Call rfresh End Select End Sub Private Sub LstGrp_Click() Set Actuf = LstGrp.parent Select Case LstGrp.Name Case "drvsLB" If Actuf.drvsLB.ListCount = -1 Then Actuf.Label17 = "" Else Actuf.Label17 = Actuf.drvsLB.text & " Drive Selected." End Select End Sub Private Function ghix() ghix = Actuf.HelpContextID Select Case Actuf.Name Case "globalsdlg" ghix = ghix + (5 * Actuf.MultiPage1.value) Case "errordlg" ghix = ghix + errnum End Select End Function Private Sub rfresh() Actuf.Label17 = "No Drive Selected.": Actuf.drvsLB.Clear: a = shwdrvlst(Actuf) End Sub Private Sub rcanit() Call ulo Unload Actuf End Sub
in a vb module (at the top)
in same vb module
Code
Display MoreSub ldbtn(me1) 'ld frm objs2 class ReDim Preserve Fobj(1, 3) Dim ctl As Control ufi = ufi + 1: tg = 0 For Each ctl In me1.Controls If TypeName(ctl) = "CommandButton" Or TypeName(ctl) = "ListBox" Then Select Case ctl.Name Case "HelpBT", "CancelBT", "RefreshBT" Set Fobj(ufi, tg).BtnGrp = ctl: tg = tg + 1 Case "drvsLB" Set Fobj(ufi, tg).LstGrp = ctl: tg = tg + 1 End Select End If Next ctl End Sub Sub ulo() If ufi = 0 Then Erase Fobj End Sub
in userform
How it works:
the Fobj() As New cFrmClk, ufi
defines a dynamic array fobj() and a global variable ufi (set to -1 initially)when a userform is shown, the userform_initialize routine will call ldbtn(Me)
the ldbtn(me1) routine will increment ufi and load each control required to the classthe sub ulo() routine simply erases the fboj() array from memory when the userform is closed
-
Re: Copy and paste Special VBA
I use the the following
CodewsSource.Range("B" & lngMyRow & ":I" & lngMyRow).Copy wsOutput11.Range("B" & lngPasteRow).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Paste:=xlValues - copies values,
Paste:=xlPasteFormulas - copies formulasfor all values, see the help on pastespecial
-
Re: Using a class to detect button click and open a form named (buttoncaption)
I had a similar problem - I called my load buttons into class from the forms
eg:
class module (cFrmClk)
Code
Display More'class cFrmClk - 2017\06\09 by Rickb Public WithEvents BtnGrp As MSForms.CommandButton Public WithEvents LstGrp As MSForms.ListBox Private Actuf Private Sub BtnGrp_Click() Set Actuf = BtnGrp.parent Select Case BtnGrp.Name Case "HelpBT" Call gethelp(ghix(ufi)) Case "CancelBT" Call rcanit(ufi) Case "RefreshBT" Call rfresh(ufi) End Select End Sub Private Sub LstGrp_Click() Set Actuf = LstGrp.parent Select Case LstGrp.Name Case "drvsLB" If Actuf.drvsLB.ListCount = -1 Then Actuf.Label17 = "" Else Actuf.Label17 = Actuf.drvsLB.text & " Drive Selected." End Select End Sub Private Function ghix(ufi) ghix = Actuf.HelpContextID Select Case Actuf.Name Case "globalsdlg" ghix = ghix + (5 * Actuf.MultiPage1.value) Case "errordlg" ghix = ghix + errnum End Select End Function Private Sub rfresh(ufi) Actuf.Label17 = "No Drive Selected.": Actuf.drvsLB.Clear: a = shwdrvlst(Actuf) End Sub Private Sub rcanit(ufi) Unload Actuf End Sub
in a VB module (at the top)
in same VB module (as above)
Code
Display MoreSub ldbtn(me1) 'ld frm objs2 class Dim ctl As Control ufi = ufi + 1: tg = 0 For Each ctl In me1.Controls If TypeName(ctl) = "CommandButton" Or TypeName(ctl) = "ListBox" Then Select Case ctl.Name Case "HelpBT", "CancelBT", "RefreshBT" Set Fobj(ufi, tg).BtnGrp = ctl: tg = tg + 1 Case "drvsLB" Set Fobj(ufi, tg).LstGrp = ctl: tg = tg + 1 End Select End If Next ctl End Sub
in initialize routine of every userform:
Explanation:
I set ufi to -1
when my userform is initialized,
it calls the ldbtn(Me) - it increments ufi and sets the button(s) click events in the classthe reason I have a ufi variable (userform index) is my userforms can call an errordlg userform, thus having two userforms at once.
ufi = 0 sets the butons for the first userform
ufi = 1 sets the buttons for the 2nd or error userformufi = 2,3,4 etc - if you have 2 or more userforms that open at once (simply adjust the fobj() array accordingly)
the Fobj(x,y) array
Fobj(0,y) = 1st userform
Fobj(1,y) = 2nd userformy = 0 to number of obj's you are trapping in ldbtn()
(I have 2 userforms that can be active and 4 obj's (hence: Fobj(1,3)) (my arrays start at 0)
once the error userform is closed, I decrement ufi to point back to the first userform -
Re: using a common class module for cancel buttons across all userforms
I am still working on the cancel click routine removals from the userform (need to figure out mouse events yet)
However,
I was able to remove all my help button click events from all my userforms and put it in a class module.Here is the code
in a class module (called cHelp)
Code
Display More'class cHelp - 2017\06\05 by Rickb Public WithEvents BtnGrp As MSForms.CommandButton Public ActUF Public Sub BtnGrp_Click() Call rhelp(ufi) End Sub Public Sub rhelp(ufi) If ufi = -1 Then hix = 0 Else ufn = HBtn(ufi).ActUF.Name hix = HBtn(ufi).ActUF.HelpContextID Select Case ufn Case "globalsdlg" hix = hix + (5 * HBtn(ufi).ActUF.MultiPage1.value) Case "errordlg" hix = hix + errnum End Select End If abtfl = parmval("myhelpfile"): Call c4fl("", "", abtfl): If cnt = 0 Then x = MsgBox("Help File Not Found!" & crlf1 & "File= " & abtfl): beep: Exit Sub ThisWorkbook.Activate: Application.Help ActiveWorkbook.Path & "\" & abtfl, hix End Sub
in a vb module
Code
Display MorePublic HBtn(1) As New cHelp, ufi Sub ldbtn(me1) Dim ctl As Control ufi = ufi + 1 For Each ctl In me1.Controls If TypeName(ctl) = "CommandButton" Then If ctl.Name = "HelpBT" Then Set HBtn(ufi).ActUF = me1: Set HBtn(ufi).BtnGrp = ctl: Exit For End If Next ctl End Sub
in userform
Code'userform calcdlg - 2017\06\02 by Rickb Private Sub UserForm_Initialize() Call ldbtn(Me) End Sub
how it works!
ufi variable (userform index) must be initialized to -1
When you .show the userform, it calls ldbtn(me) -where me is the userform object
the ldbtn sub routine sets helpbt click event control as well as passing the userform object (me) to the class(note my created object class hbtn(1) is an array to store 2 userforms. 1 for the initial userform and 1 in case the error userform is invoked)
so hbtn(0) holds the main userform objects
hbtn(1) will hold the error userform objectsufi in ldbtn() is incremented to 0 and the class gets set with the main userform help event
if an error happens that invokes the error userform while the main userform is up, ufi gets incremented to 1
and hbtn(1) gets loaded with the error useform help event(note in my program, the error userform is the only form that loads while another is active)
in the cHelp class the btngrp_click event will fire when the helpbt is pressed
it will use the ActUF (passed userform object (Me))
to get the helpcontext index to pass to the application.helpnote: 1 of my userforms has a multi page so I check for that userform and adj the helpindex (hix) accordingly
that's it.
Please note, when you show a second userform, it increments ufi variable, when you unload it you must decrement it by 1
so it points to the main userform in hbtn(0)also, I have help buttons on spread sheets ufi of -1 tells me a userform did not call it
so that the rhelp routine knows enough to avoid code that has userform references Eg: AcUFon help buttons on the sheets can call the clas like this
This works great and eliminates all HelpBT_Click Events from all userforms and puts it in a single class module
-
I have a Cancel button on all my userforms,
I would like to create a class module to handle all cancel button click events in any userform I'm inI have looked extensively online and all of the code for this is for 1 userform with a bunch of buttons.
I want to eliminate all the cancel button_click events from all my userforms and use a single class module to do this event.
My userforms are not dynamically created they were created in the project pane.
--
I managed to find my a solution after playing for a while.
created class module called BtnClass
Code'class BtnClass - 2017\05\31 by Rickb Public WithEvents ButtonGroup As MSForms.CommandButton Public Parent As Object Private Sub ButtonGroup_Click() x = MsgBox(ButtonGroup.Name): beep Unload Parent End Sub
created sub routine in a vb module
Code
Display MoreSub ldbtn(me1) Dim ctl As Control For Each ctl In me1.Controls If TypeName(ctl) = "CommandButton" Then If ctl.Name = "CancelBT" Then Set Buttons(1).ButtonGroup = ctl Set Buttons(1).Parent = me1 End If End If Next ctl End Sub
added dim beginning of my main module
-
Re: VBA to Automatically Add to Drop Down Menu and check for Duplicattes
your if/endif statements are not in proper sequence.
Code
Display MoreIf inputWks.Range("MachineName") = True Then MsgBox "Machine already exists. Please select from dropdown." Exit Sub Else If inputWks.Cells("MachineName") = False Then lRsp = MsgBox("Machine not in database. Add to dropdown?", vbQuestion + vbYesNo, "New Machine") If lRsp = vbYes Then Range("MachineList").Cells(Range("MachineList").Rows.Count + 1, 1) = Range("$J$6") Else MsgBox "Please select Machine that is in the database." End If End If End If End Sub
-
Re: UserForm Input to a Specific Row
I have attached a workbook showing how to use indexing in the userform
the advantage being you can error check fields be putting into the spreadsheetI have attached to spread sheets,
MY_Beta_Housing_Assignment_Tool 2_1.xlsm -uses address to select
MY2_Beta_Housing_Assignment_Tool 2_1.xlsm -uses housing unit to select