Invalid use of property vba ошибка

I have the Student class in VBA (Excel) implemented as follows Option Explicit Private name_ As String Private surname_ As String Private marks_ As New Collection Public Property Get getMean() As

I have the Student class in VBA (Excel) implemented as follows

Option Explicit

Private name_ As String
Private surname_ As String
Private marks_ As New Collection


Public Property Get getMean() As Single

    Dim sum As Double
    Dim mark As Double
    Dim count As Integer

    For Each mark In marks_
        sum = sum + mark
        count = count + 1
    Next mark

    getMean = sum / count

End Property

Public Property Let setName(name As String)
    name_ = name
End Property

Public Property Get getName() As String
    getName = name_
End Property

Public Property Let setSurname(surname As String)
    surname_ = surname
End Property

Public Property Get getSurname() As String
    getSurname = surname_
End Property

Then I have a main sub where I write:

Dim stud1 As New Student

stud1.setName "Andy"

I got a compile error on stud1.setName "Andy" : Invalid use of property.
I don’t understand why. Any Idea, please?

Community's user avatar

asked Feb 1, 2014 at 20:06

mStudent's user avatar

2

Since it’s a property (not method) you should use = to apply a value:

Dim stud1 As New Student

stud1.setName = "Andy"

BTW, for simplicity, you can use the same name for get and set properties:

Public Property Let Name(name As String)
    name_ = name
End Property

Public Property Get Name() As String
    Name = name_
End Property

and then use them as follows:

Dim stud1 As New Student
'set name
stud1.Name = "Andy"
'get name
MsgBox stud1.Name

AAA's user avatar

AAA

3,4501 gold badge14 silver badges31 bronze badges

answered Feb 1, 2014 at 20:07

Dmitry Pavliv's user avatar

Dmitry PavlivDmitry Pavliv

35.1k13 gold badges79 silver badges80 bronze badges

3

Joe4

Joe4

MrExcel MVP, Junior Admin


  • #2

What is the purpose of that «f9» in there for? It shouldn’t be there.
You can also combine the two rows toegether (you seldom need a «.Select» followed by a «Selection.»).
So all of this:

Code:

Range("f9").Select
   ActiveCell.[COLOR=#ff0000]Formula[/COLOR] "f9" = "=IF(OR(K9=0,m9=0,m9=""misc.""),m9,m9-k9)"
    Range("G9").Select
    ActiveCell.Formula "g9" = "=IF(OR(j9=0,n9=0),n9,n9-j9)"

can be combined like this:

Code:

Range("f9").Formula = "=IF(OR(K9=0,m9=0,m9=""misc.""),m9,m9-k9)"
Range("G9").Formula = "=IF(OR(j9=0,n9=0),n9,n9-j9)"

Last edited: Mar 29, 2016

  • #3

Hi

Remove the «f9» and «g9» and your code should work OK.

HTH

Dave

  • #4

Thanks Joe & Dave — I’m not sure it works because now I’m stuck the first part of the code.
I have column «I» which a person will enter a {y, n, ok}.
However, I want these to be changed via formatting. I want the y = green smiley face. I want n = red x. And I want ok = blue checkmark.
I used 3 types of formatting as listed — see very beginning of code below. However, when I try to run the code now I get a Run-time error ‘424’: Object required. I can’t remember now if it was the 1st or 2nd line of the code see green highlights. Also, when it stepped on I came to another error (see purple highlight). The error was «Compile error: Invalid use of property. The orange highligt is this error «Runtime error 1004: Application define or Object defined error»
Any ideas?

Rich (BB code):

Sub Monthly_NOs_Update()
'
' Monthly_NOs_Update Macro
' Column F-ColumnD Column G-ColumnC
'
' Keyboard Shortcut: Ctrl+m
   If Target.Column = 9 Then
        If Target.Value = "y" Then
            With Target
                .Font.Name = "Carta"
                .Value = "J"
            End With
        End If
        If Target.Value = "n" Then
            With Target
                .Font.Name = "Bookshelf Symbol 7"
                .Value = "i"
            End With
        End If
        If Target.Value = "ok" Then
            With Target
                .Font.Name = "ZDingbats"
                .Value = "4"
            End With
        End If
    End If
    Columns("C:G").Select
    Selection.Copy
    Range("j9:n9").Select
    ActiveSheet.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
   Range("f9").Formula = "=IF(OR(K9=0,m9=0,m9=""misc.""),m9,m9-k9)"
Range("G9").Formula = "=IF(OR(j9=0,n9=0),n9,n9-j9)"
    Range("F9:G9").Select
    Selection.Copy
    Range("F10:F17").Select
    ActiveSheet.Paste
    Range("F19:F23").Select
    ActiveSheet.Paste
    Range("F25:F30").Select
    ActiveSheet.Paste
    Range("F32:F36").Select
    ActiveSheet.Paste
    Range("F37:F39").Select
    ActiveSheet.Paste
    Range("F40:F42").Select
    ActiveSheet.Paste
    Range("F43:F45").Select
    ActiveSheet.Paste
    Range("F46:F48").Select
    ActiveSheet.Paste
    Range("f49:f51").Select
    ActiveSheet.Paste
    Range("f53:f64").Select
    ActiveSheet.Paste
    Columns("F:G").Select
    Range("j10:n10").Select
    Selection.Copy
    Columns("F:G").Select
    ActiveSheet.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Columns("j:n").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
Dim rng As Range
Application.ScreenUpdating = False
For Each rng In Range("c9:d64")
    With rng
        If .Value > 0 Then .ClearContents
        If .Offset(, x).Value = 0 Then .Offset(, x).ClearContents
    End With
Next rng
Application.ScreenUpdating = True
    fName = ActiveWorkbook.FullName
    fName = Left(fName, InStrRev(fName, ".") - 1) & ".xlsm"
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
   Application.ScreenUpdating = False
    Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    'insert first sheet name in next line
    If Not ws.Name = "Sheet1" Then ws.PrintOut
Next ws
End Sub

Last edited: Mar 29, 2016

  • #5

I’m sure Joe4 will correct me if I’m wrong, but it looks like you’re running this as a standalone macro…Target would need to be declared as something, it would work OK if you were running from a worksheet event.

The next bit might be down to you selecting the entire column and then pasting into row 9, that size of the copied range wouldn’t fit.

If you could put in words what it’s to do I’ll try and tidy it up for you ;)

Joe4

Joe4

MrExcel MVP, Junior Admin


  • #6

I’m sure Joe4 will correct me if I’m wrong, but it looks like you’re running this as a standalone macro…Target would need to be declared as something, it would work OK if you were running from a worksheet event.

Good catch. I missed that.

«Target» is used in Event Procedures. I suppose you could use it as a variable in standalone procedure, though you would need to define it, which you haven’t done (so «Target» actually is nothing in your procedure).

  • #7

I am trying to Copy & Paste as Value Columns C:G to Columns J:N.
I then want to put a formula in f9 and g9. (This you have already helped me on).
Then I want to copy the formulas in f9 and g9 down through the various groups of rows. Ultimate end is for all rows in columns C:D are cleared for next months data input.
Once this is done, I want to copy & paste as value C:G and Delete J:N.
I would like for the clerk to be able to enter «y», «n», «ok» and have the code change the formatting to reflect a green «smiley face»,a red «X» and a blue «checkmark».
Then I would like to clear contents for any data entered into the same various group of rows but only in Columns C & D.
Finally, I would like the file to be saved.
Thanking you all in advance for any help!

Last edited: Mar 29, 2016

  • #8

Can you all explain what you mean by a «standalone macro» (vs. what) and Event procedures and variable in a standalone macro. I’m trying very hard to learn VBA on my own so I needn’t bother good folks like you all. I would like to be one of the people helping others. Someday perhaps.

Joe4

Joe4

MrExcel MVP, Junior Admin


  • #9

Event Procedure code is a «special» kind of VBA code. It is VBA that is automatically triggered upon some «event» happening, like opening the file, changing a cell, selecting a cell, saving a file, etc. In order for it to work, it needs to follow strict rules, specifically it has to be located in the proper Workbook or Worksheet module and must be named a certain way (there is no flexibility in that). See here for more details on it: Events In Excel VBA

Then there are procedures that you create yourself and put in standard modules. These can be named most anything you like (following some basic naming convention rules). These do not run automatically. Usually, your assign these to a keyboard shortcut, a command button, or simply run them through the Macro menu. The main point being, is you need to explicitly do something in order to run these macros. User Defined Functions also fall into this category.

  • #10

Hi dstepan

Am I to take it there will be three happenings here?

1. You set up the spreadie.
2. Your clerk enters the y, n, ok (deleting the values from columns C&D on that row)
3. You finalise the spreadie

Is that the general run of it?

Thanks

Dave

  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • [RESOLVED] Compile error: Invalid use of property

  1. Jul 9th, 2010, 06:46 AM


    #1

    Arispan is offline

    Thread Starter


    Lively Member

    Arispan's Avatar


    Resolved [RESOLVED] Compile error: Invalid use of property

    Hello everyone,

    I’m making a big project (my biggest project) but I get a «Compile error: Invalid use of property» message.

    Here’s my code:

    vb Code:

    1. Private CForm As Form

    2. Public Sub Initialize(Child As Form)

    3. CForm = Child 'This line gives the error

    4. End Sub

    When I call my «Initialize» sub from another form, I get this error.
    Can someone help me ?

    Last edited by Arispan; Jul 9th, 2010 at 06:51 AM.


  2. Jul 9th, 2010, 06:50 AM


    #2

    Re: Compile error: Invalid use of property


  3. Jul 9th, 2010, 06:55 AM


    #3

    Arispan is offline

    Thread Starter


    Lively Member

    Arispan's Avatar


    Re: Compile error: Invalid use of property

    Thanks baja_yu! Now everything works fine !

    P.S. I think my thread just broke a record («the fastest solved thread in vforums»).

    Last edited by Arispan; Jul 9th, 2010 at 08:23 AM.


  • Home
  • VBForums
  • Visual Basic
  • Visual Basic 6 and Earlier
  • [RESOLVED] Compile error: Invalid use of property

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules


Click Here to Expand Forum to Full Width

analyst

437 / 144 / 9

Регистрация: 12.01.2009

Сообщений: 678

Записей в блоге: 1

1

12.02.2010, 16:42. Показов 11666. Ответов 2

Метки нет (Все метки)


Всем привет! При использовании свойства path возникает ошибка:
Compile error: Invalid use of property

Visual Basic
1
2
3
Sub fen()
ThisWorkbook.Path
End Sub

Пример использования данной конструкции нашёл здесь:

В чем может быть ошибка (кроме отсутствия у меня мозгов)?



0



EducatedFool

0 / 0 / 0

Регистрация: 28.09.2009

Сообщений: 88

12.02.2010, 16:55

2

При использовании свойства path возникает ошибка

Что-то в вашем коде я не вижу использования этого свойства…

Использовать его надо хоть как-то, а то VBA получает значение этого свойства, а что с ним дальше делать — не знает…

Visual Basic
1
2
3
4
5
Sub fen()
    x = ThisWorkbook.Path
    'или
    MsgBox ThisWorkbook.Path
End Sub



0



437 / 144 / 9

Регистрация: 12.01.2009

Сообщений: 678

Записей в блоге: 1

12.02.2010, 16:59

 [ТС]

3

Цитата
Сообщение от EducatedFool
Посмотреть сообщение

Что-то в вашем коде я не вижу использования этого свойства…

Использовать его надо хоть как-то, а то VBA получает значение этого свойства, а что с ним дальше делать — не знает…


Спасибо!) Пора спать)



0



Вопрос:

Я знаю, что есть тонны нитей и вопросов об этом, и это довольно очевидно, как правило, где ошибка. Большинство людей не используют ключевое слово SET при перемещении объектов. Я.

Вот что происходит:

Это находится на листе excel, поэтому я сделал небольшой набор функций для отслеживания столбцов и создания индекса, чтобы каждый раз, когда приложение запускает его, он будет переиндексировать столбцы, чтобы я мог делать такие вещи, как .Cells(row_num, pCust_index("custID")) в случае изменения столбца.

У меня есть форма custContagions. Это просто небольшое модальное окно, которое позволяет пользователям добавлять/удалять/редактировать зараженный клиентом статус. Он содержит свойство:

Private pCust_index as dictionary

Он также содержит этот набор свойств:

Public Property Set set_cust_index(ByRef custIndex As Dictionary)
Set pCust_index = New Dictionary
Set pcust_index = custIndex
End Property

Довольно прямо вперед? Принимает объект словаря, сбрасывает мой индекс и указывает на существующий переданный объект.

Теперь, в вызывающей форме у меня есть другая сторона:

Private Sub newCustContagious_LBL_Click()
Dim contForm as New custContagions
Call contForm.set_cust_index(pCust_index)  'note pCust_index is a private here too
Call contForm.Show
...

Я получаю ошибку Invalid Use of Property compiler при вызове set_cust_index.

Что я упустил?

Лучший ответ:

Большинство людей не используют ключевое слово SET при перемещении объектов вокруг

Затем они не движутся вокруг объектов. Ключевое слово Set – способ перемещения объекта вокруг.
Существует также CopyMemory чтобы напрямую копировать ObjPtr, но я не считаю, что большинство людей это делают.

Довольно прямо вперед?

Не совсем. Вы создаете словарь, немедленно отбрасываете его и заменяете другим словарем, переданным в качестве параметра. Вы должны удалить первую из двух строк и создать параметр ByVal:

Public Property Set set_cust_index(ByVal custIndex As Dictionary)
    Set pcust_index = custIndex
End Property

Я получаю ошибку компилятора Invalid Use of Property

Вы объявили свойство, а затем использовали его как суб. С собственностью вы должны были сделать:

Set contForm.set_cust_index = pCust_index

В этот момент имя set_cust_index не выглядит великолепно. Это сделало бы разумное имя для sub (Public Sub set_cust_index(ByVal custIndex As Dictionary)), но для свойства вам было бы лучше с Public Property Set cust_index(ByVal custIndex As Dictionary).

  1. 10-08-2015, 12:31 PM


    #1

    tvwright is offline


    Registered User


    VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Hi all,

    I’m trying to create a code for cell G20 (see attached workbook), which represents a value for «intercept». This «intercept» value changes, depending on multiple conditions, which is why I need to write a complex nesting IF function with multiple AND conditions to get the correct value. Currently, I have only six nesting IFs, but eventually I will need 963. I am just testing this out to see if I can get six going and then I will worry about the remaining 957 lol.

    So here is my code to accomplish this:

    Sub IfThenNesting()

    If C3 = «CCI» And C5 = «Case-Shiller National Home Price Index» And C9 = 5 Then Range(«I4»).Value
    End If
    ElseIf C3 = «CCI» And C5 = «National Unemployment Rate» And C9 = 0 Then Range(«I5»).Value
    End If
    ElseIf C3 = «CCI» And C5 = «S&P 500 Stock Prices» And C9 = 0 Then Range(«I6»).Value
    End If
    ElseIf C3 = «CCI» And C5 = «# of House Units Starts» And C9 = 3 Then Range(«I7»).Value
    End If
    ElseIf C3 = «National Unemployment Rate» And C5 = «S&P 500 Stock Prices» And C9 = 0 Then Range(«I8»).Value
    End If
    ElseIf C3 = «S&P 500 Stock Prices» And C5 = «Nordstrom Stock Price» And C9 = 0 Then Range(«I9»).Value
    End If
    End Sub

    and my workbook is attached here:
    VBA IF test.xlsx

    I want to do a nesting IF statement with multiple conditions. It all makes sense if you look at the worksheet. I want the calculation of the IF statement to be entered into cell G20.

    Any help is GREATLY appreciated on getting me started. THANK YOU.

    Last edited by tvwright; 10-08-2015 at 12:49 PM.


  2. 10-08-2015, 12:34 PM


    #2

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Get rid of every «End If» and «ElseIf» — you really are not using nesting at all.

    But your code has other problems: if your C3, C5, and C9 are cells , then use

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «Case-Shiller National Home Price Index» And Range(«C9»).Value = 5 Then Range(«G19»).Value = Range(«I4»).Value

    But if you expect 900+ nested ifs then you really should be doing something different.

    Last edited by Bernie Deitrick; 10-08-2015 at 12:41 PM.

    Bernie Deitrick
    Excel MVP 2000-2010


  3. 10-08-2015, 12:42 PM


    #3

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    Get rid of every «End If» and «ElseIf»

    But your code has other problems: if your C3, C5, and C9 are cells , then use

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «Case-Shiller National Home Price Index» And Range(«C9»).Value = 5 Then Range(«I4»).Value = «Something»

    OK Great, did that. Still get the same «Compile Error: Invalid Use of Property» on the very first line of code.

    The error is highlighting this line of code:

    FirstLine.png

    Also, how do I get it so that it enters this IF formula into cell G20? Thank you!


  4. 10-08-2015, 12:45 PM


    #4

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    Get rid of every «End If» and «ElseIf» — you really are not using nesting at all.

    But your code has other problems: if your C3, C5, and C9 are cells , then use

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «Case-Shiller National Home Price Index» And Range(«C9»).Value = 5 Then Range(«G19»).Value = Range(«I4»).Value

    But if you expect 900+ nested ifs then you really should be doing something different.

    OK — I still get the same error with the first line even after making those ‘Range(«C9»).Value’ updates for all of my cell values. what are other options that I should be doing other than nesting IF statements? Keep in mind, I am not a VBA coder so I was trying to keep it simple even though it is very repetitive.

    My code now currently reads like this and still get the error on first line:

    Sub Test()
    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «Case-Shiller National Home Price Index» And Range(«C9»).Value = 5 Then Range(«I4»).Value

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «National Unemployment Rate» And Range(«C9»).Value = 0 Then Range(«I5»).Value

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «S&P 500 Stock Prices» And Range(«C9»).Value = 0 Then Range(«I6»).Value

    If Range(«C3»).Value = «CCI» And Range(«C5»).Value = «# of House Units Starts» And Range(«C9»).Value = 3 Then Range(«I7»).Value

    If Range(«C3»).Value = «National Unemployment Rate» And C5 = «S&P 500 Stock Prices» And Range(«C9»).Value = 0 Then Range(«I8»).Value

    If Range(«C3»).Value = «S&P 500 Stock Prices» And C5 = «Nordstrom Stock Price» And Range(«C9»).Value = 0 Then Range(«I9»).Value

    End Sub

    Last edited by tvwright; 10-08-2015 at 12:54 PM.


  5. 10-08-2015, 01:01 PM


    #5

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    First, you are putting your code into the wrong place. Delete the code that you have, then double-click the Module1 object in your project, and paste this into the window that appears. You were getting the error on the first line because the sub was not compiling, because you were using

    …. Then Range(«I4»).Value

    without assigning a value to I4 or using I4’s value in any way.


  6. 10-08-2015, 01:40 PM


    #6

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    First, you are putting your code into the wrong place. Delete the code that you have, then double-click the Module1 object in your project, and paste this into the window that appears. You were getting the error on the first line because the sub was not compiling, because you were using

    …. Then Range(«I4»).Value

    without assigning a value to I4 or using I4’s value in any way.

    Thank you. Copying and pasting the above code worked!!! WOW. I am very thankful for your help and it makes sense. Except I made a typo in my first post and said G19 when I meant G20 so I will change it. You’re awesome! THANK YOU.

    Except now I have to press «run» anytime I want G20 to update. How do I have it automatically run anytime someone changes any of the criteria in cells C3, C5, and or C9?

    Last edited by tvwright; 10-08-2015 at 01:43 PM.


  7. 10-08-2015, 01:45 PM


    #7

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Great! Get yourself a good book — I always recommend John Walkenbach’s «Excel XXXX Power Programming With VBA» series — available for older versions used (and cheaper), but the basics still apply, so it is a good start:

    http://www.amazon.com/gp/offer-listi…condition=used


  8. 10-08-2015, 01:49 PM


    #8

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    Great! Get yourself a good book — I always recommend John Walkenbach’s «Excel XXXX Power Programming With VBA» series — available for older versions used (and cheaper), but the basics still apply, so it is a good start:

    http://www.amazon.com/gp/offer-listi…condition=used

    Thank you. I will definitely get a book. I added an «edit» after I already hit submit… one more quick question: how do I get the code to automatically run anytime the conditions in cells C3, C5 and/or C9 are changed?


  9. 10-08-2015, 02:00 PM


    #9

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    1) Copy this code.
    2) Right-Click the sheet tab of interest.
    3) Select «View Code»
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed to the macro name


  10. 10-08-2015, 02:15 PM


    #10

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)


  11. 10-14-2015, 01:57 PM


    #11

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    1) Copy this code.
    2) Right-Click the sheet tab of interest.
    3) Select «View Code»
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed to the macro name

    Hi Bernie,

    I ordered that book from Amazon and it hasn’t come yet. But I’m excited to be getting it next week. So I have another question regarding this project for you since you have been so great at helping! Attached is my updated workbook. Everything is working correctly and flawlessly, thanks to your help.

    Right now all of my data and calculations are on the same sheet, but I would like to move the data to sheet 2, and have my calcuations on sheet 1 so I don’t have to be looking at all the data on the form. Here is the workbook for reference:

    La la.xlsm

    Here is my code for reference:

    In Module1

    In Sheet 2

    So all of the above code works perfectly. Except now I have all the data on sheet named «Calculation» in the same position except on sheet named «data». I want the VBA code to use the cells on worksheet named «Data» instead of the current cell ranges it is using on worksheet named «calculation.

    I tried changing all of the above to

    but this did not work? Can you send me in the right direction to how to keep the code working properly by changing the data to another sheet?

    Thank you! <3

    Last edited by tvwright; 10-14-2015 at 02:03 PM.


  12. 10-14-2015, 02:50 PM


    #12

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    You don’t have a worksheet name «data» in the posted file.

    So try this. Change

    to


  13. 10-14-2015, 02:58 PM


    #13

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    I Am so sorry. I updated the worksheet names and didn’t save it before I sent you the file. You got the older version. Here is the new version. Will your code still work? I will go ahead and try it in a minute.

    La la.xlsm


  14. 10-14-2015, 03:58 PM


    #14

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    You should just use a formula in those three cells:

    B28:

    =SUMPRODUCT((F4:F15=C3)*(G4:G15=C5)*I4:I15)

    B29:

    =SUMPRODUCT((F4:F15=C3)*(G4:G15=C5)*H4:H15)

    C19

    =INDEX(J:J,SUMPRODUCT((F4:F15=C3)*(G4:G15=C5)*ROW(H4:H15)))

    When you have a larger table just change the 15s to the a number higher than the number or rows in your table.

    In code, you would use:

    Last edited by Bernie Deitrick; 10-14-2015 at 04:03 PM.


  15. 10-14-2015, 04:24 PM


    #15

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    You don’t have a worksheet name «data» in the posted file.

    So try this. Change

    to

    Hi Bernie,

    Thank you. It says I have a Run Time Error when I enter that code. I replaced all cell values to have the sheet reference preceding it. Here is my code now after following your update:

    and I get «Run-Time error ‘424’ Object Required» pop up. It highlights my sixth line of code, see picture below:

    delete.png


  16. 10-14-2015, 04:25 PM


    #16

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Also here is my workbook now. It has no data in the calculation tab.

    La la.xlsx

    Any idea on why I’m getting that error? Thank you!


  17. 10-14-2015, 04:34 PM


    #17

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    OK I got it to work. THe issue was I did not have a T in the «shtd» or «shtc» in this part:

    Corrected version:

    it used to be..
    Incorrect version:

    I added the T, and it works when I manually «run» the code, but it is no longer automatically updating. The code you gave me to get it to automatically update is no longer applicable because I changed the sheet.How do I get it to run automatically again? I copied the code into the «data» sheet’s code dialogue, but this does not work.

    EDIT: OK so weirdly enough, i closed out of excel and re-opened it and now it all works automatically without any problems. this is so confusing! Thank you again for all of your help.

    Last edited by tvwright; 10-14-2015 at 06:58 PM.


  18. 10-15-2015, 10:31 AM


    #18

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Great — glad to hear you got it to work, despite my poor typing skills


  19. 10-20-2015, 10:34 AM


    #19

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    1) Copy this code.
    2) Right-Click the sheet tab of interest.
    3) Select «View Code»
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed to the macro name

    Hi Bernie,

    I have a few more macros that I would like to automatically run when those same cells are changed. The above code currently only works to run my first macro called «Test». I have 5 additional macros now that I would also like to run in the same way, named «Test1» «Test2» «Test3» «Test4» and «Test5» without the quotation marks. How do I edit your above code to get them to run in the same way as my first macro called «Test»?

    I attempted to change the code to this, but it did not work:

    How do you advise?

    Also I got the book you recommended and have already read Part 1 — it was just the introductory stuff. The next part is more advanced, and I’m very excited to read it tonight!


  20. 10-20-2015, 12:16 PM


    #20

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)


  21. 10-20-2015, 12:54 PM


    #21

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    Thanks, but when I do that it triggers a window with a drop down menu prompting me to select which single macro of the 11 I would like to run. See image below:

    MacroList.png

    I would like to select ALL macros and run them at the same time. I had to make 11 different macros, because I kept getting an error that the procedure was «too long» so I had to divide the one long procedure into multiple procedures. Do you have any suggestions?

    Thank you so much!


  22. 10-20-2015, 03:50 PM


    #22

    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Post your workbook.

    Did you look at using the formula that I posted instead of macro code?


  23. 10-20-2015, 03:59 PM


    #23

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    Quote Originally Posted by Bernie Deitrick
    View Post

    Post your workbook.

    Did you look at using the formula that I posted instead of macro code?

    Sorry for the late reply Bernie, usually I get an email notification when you respond but this time I did not for some reason. I did not look at the formula you posted, no. Do you think I should do that still — here is my workbook:

    La la (Autosaved).xlsm

    Let me know! Thank you.

    EDIT:

    It appears that your formula method is working!!!!!!!!!!!!!!! WOW. THANK YOU~

    Last edited by tvwright; 10-20-2015 at 04:33 PM.


  24. 10-20-2015, 05:00 PM


    #24

    tvwright is offline


    Registered User


    Re: VBA Noob, «Compile Error: Invalid Use of Property» On First line of Code (great..)

    If you’re interested, here is the final worksheet (for now… )

    La la Final.xlsm

    Last edited by tvwright; 10-20-2015 at 05:22 PM.


Понравилась статья? Поделить с друзьями:
  • Invalid token pubg ошибка
  • Invalid timestamp libapp md5 checksum error на литрес что делать
  • Invalid timestamp libapp md5 checksum error на литрес на айфон
  • Invalid text representation 7 error invalid input syntax for type integer
  • Invalid text representation 7 error invalid input syntax for type bigint