if isempty question

devj364

New Member
Joined
Apr 30, 2018
Messages
4
Ok, so I am relatively new to vba and i need to show a userform if a cell is empty, but for some reason it is not running correctly. Could i get some help or advice on how to better handle please.:)


Sub Auto_Open()


Worksheets("Report Disposition").Activate


If IsEmpty("D3:J3") Then


UserForm1.Show


Else


Worksheets("Variable Data").Activate


End If


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi devj364,

Welcome to MrExcel!!

I don't think the IsEmpty function can handle a range so try this that simply uses the COUNTA worksheet function:

Code:
Option Explicit
Sub Auto_Open()

    Worksheets("Report Disposition").Activate
    If Evaluate("COUNTA(D3:J3)") = 0 Then
        UserForm1.Show
    Else
        Worksheets("Variable Data").Activate
    End If

End Sub

Must say seeing Auto_Open brought a smile as I used that in the 90's and haven't seen it for a long time :) Most people now use the Workbook_Open event macro.

Thanks,

Robert
 
Upvote 0
thanks that helped out thanks!!!

I am still figuring things out. But. if you have a second or two i would like to know the difference in Auto_Open and Workbook_Open event?

 
Upvote 0
Glad we got it sorted :)

To use the workbook event macro follow these five steps:

1. Open the Visual Basic Editor (Alt + F11)
2. Click on ThisWorkbook in the Project - VBAProject left-hand panel
3. Click on the left-and side drop-down and select Workbook
4. Click on the right-hand side drop-down and select Open (this may have already been selected by default)
5. Put the code you want to run whenever the workbook is opened here

Note your Auto_Open macro will work too but it is old school now and there's other workbook events you can also use using the steps above.

HTH

Robert
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,410
Messages
6,124,755
Members
449,187
Latest member
hermansoa

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