UserForm coding - getting a Compile error: Member already exists in an object module from which this object module derives

CWMacNut

New Member
Joined
Dec 28, 2018
Messages
11
I am working on building a UserForm to enter data into an Excel sheet. I have created the UserForm, named all my controls and objects. I am now coding what should happen when the Submit button is clicked. The first thing to do is to declare my variables, right? I have created all the SUBs I will need (one for each object and filled with just comments at this point). So, I go to work on the first SUB and I get this error and it highlights my first object's variable name.

Compile error: Member already exists in an object module from which this object module derives

So I comment out the DIM statements and I get this error and it highlights the first object's variable name the first time it's used.

Compile error: Invalid use of property

I am stuck! I understand that there is possibly a circular reference somewhere but I just don't see it.

Code:
Dim CurrentWorksheet$
Dim HeaderCount%
Dim HeaderNames As Variant
Dim LastCell As Range
Dim FirstBlankCell As Range
'Dim JobNumNEW$
'Dim PRINTERS$
'Dim TodaysDate$
'Dim Time_Start$
'Dim Time_End$
'Dim Time_Total$
'Dim Duplex_YES$
'Dim Duplex_NO$
'Dim NumPrints$
'Dim Color_YES$
'Dim Color_NO$

Private Sub Button_Submit_Click()
        
        CurrentWorksheet = ActiveSheet.Name
        Range("A1").Select

' ================ clear all variables

        Set JobNumNEW = ""
        Set PRINTERS = ""
        Set TodaysDate = ""
        Set Time_Start = ""
        Set Time_End = ""
        Set Time_Total = ""
        Set Duplex_YES = ""
        Set Duplex_NO = ""
        Set NumPrints = ""
        Set Color_YES = ""
        Set Color_NO = ""

' ================  populate HeaderNames

        HeaderCount = Range(Selection, Selection.End(xlToRight)).Count
        HeaderNames = Application.Index(Range("A1", Range("A1").End(xlToRight)).Value, 1, 0)

' ================ determine LastCell & FirstBlankCell

        Range("A3").End(xlDown).Select
        Set LastCell = Application.Selection
        ActiveCell.Offset(1, 0).Select
        Set FirstBlankCell = Application.Selection
        
        MsgBox ("Last cell is: " & LastCell & " . First blank cell is: " & FirstBlankCell & " .")

' ================

'       JobNum() called

' ================

[COLOR=#ff0000][B]intentional break in code (irrelevant)[/B][/COLOR]

' ================

Sub JobNum()
        ' What to do with the job number entered goes here
        ' Name: JobNumNEW
        a = 1  ' ("A1")
        For a = 1 To HeaderCount
                If HeaderNames(a) = "Job #" Then...

If anyone can help, it would be greatly appreciated! This is the biggest project I have ever attempted and I am sure I will have more questions down the road.

Thank you,
CWMacNut
Graphics Engineer
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Do you have a sub or variable that has the same name as a control in your UserForm?

Also, which line is highlighted? I've read your post twice and I don't think you've told us

This is also wrong:
Code:
        Set JobNumNEW = ""
        Set PRINTERS = ""
        Set TodaysDate = ""
        Set Time_Start = ""
        Set Time_End = ""
        Set Time_Total = ""
        Set Duplex_YES = ""
        Set Duplex_NO = ""
        Set NumPrints = ""
        Set Color_YES = ""
        Set Color_NO = ""

You don't "Set" strings, only objects - some of them also don't look like strings so you may get a type mismatch when you run the code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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