??? Userform and Macro code should work but it doesnt

friso

New Member
Joined
Apr 1, 2002
Messages
25
Hello,

Ik have a relative long Macro that needs to be executed when a userform is displayed.

First i put the macro code outside the userform, the macro therefore was only executed when the userform was closed.

After this i put the exact same code in the userform. But now all i get to see is a white userform and excel crashing on it :(

any one knows how you should do these two tasks simultaniously?

my code:

Sub mysub1()

Consolform.Show
ButtonInfra_Click
Consolform.ConsolLabel2.Caption = "l"
ButtonProducts_Click
Consolform.ConsolLabel2.Caption = "ll"
ButtonProcesses_Click
Consolform.ConsolLabel2.Caption = "lll"
ButtonEA_Click
Consolform.ConsolLabel2.Caption = "llll"
ButtonCIB_Click
Consolform.ConsolLabel2.Caption = "llll"
ButtonRM_Click
Consolform.ConsolLabel2.Caption = "lllll"

End Sub

This didn't work at all, next i put the code inside the userform this caused excel to crash.

Thanks for helping out.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
how do i set a msgbox to read as a list..eg
a
b
c
d
e

instead of a b c d e

is it vbleft or something?

i keep going blank
 
Upvote 0
Hi friso. You need to divide the code as following.
Please try.

<pre>
'--- into a standard module--from here-
Sub mysub1()
Consolform.Show
End Sub
'--- to here ---------------------------

'--- into a Consolform module--from here-
Private Sub ButtonInfra_Click()
Call PvtMysub("l")
End Sub

Private Sub ButtonProducts_Click()
Call PvtMysub("ll")
End Sub

Private Sub ButtonProcesses_Click()
Call PvtMysub("lll")
End Sub

Private Sub ButtonEA_Click()
Call PvtMysub("llll")
End Sub

Private Sub ButtonCIB_Click()
Call PvtMysub("llll")
End Sub

Private Sub ButtonRM_Click()
Call PvtMysub("lllll")
End Sub

Private Sub PvtMysub(strCaption As String)
ConsolLabel2.Caption = strCaption
End Sub
'--- to here ---------------------------
</pre>
 
Upvote 0
So what you're saying is, that as soon as the userform is diplayed, you want the macro to run, right? If this is so, what's the name of your macro?
 
Upvote 0
hi this is the entire code for the macro:


Sub ShowIt_Now()
Consolform2.Show
End Sub

Sub ShowIt_Now2()
Consolform2.Hide
End Sub




Sub ButtonKolomConsol_Click()
ShowIt_Now
ButtonInfra_Click
Consolform2.Label2.Caption = "l"
ButtonProducts_Click
Consolform2.Label2.Caption = "ll"
ButtonProcesses_Click
Consolform2.Label2.Caption = "lll"
ButtonEA_Click
Consolform2.Label2.Caption = "llll"
ButtonCIB_Click
Consolform2.Label2.Caption = "llll"
ButtonRM_Click
Consolform2.Label2.Caption = "lllll"
Worksheets("Consol-Kolom").Select
Range("A3:BB602").Select
Selection.Clear

Worksheets("DB-Kolom").Select
Range("A1:BD595").Select
Application.CutCopyMode = False
Selection.Copy
Worksheets("Consol-Kolom").Select
Range("A3:BD597").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False


Dim rRange As Range
With Sheets("Consol-Kolom")

Set rRange = .Range("A3", .Range("A65536").End(xlUp)).Offset(0, 70)

rRange.FormulaR1C1 = "=IF(RC[-68]=RC[-69],1,"""")"

Set rRange = rRange.SpecialCells(xlCellTypeFormulas, _
xlNumbers)
rRange.EntireRow.Delete
End With

ShowIt_Now2
Worksheets("Consol-Kolom").Select
Range("A1").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top