+ Reply to Thread
Results 1 to 16 of 16

Getting error invalid or unqualified reference

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Getting error invalid or unqualified reference

    Hi,
    I am getting error invalid or unqualified reference. If I copy-paste special-value then the superscript macro in the sheet module didn’t work. So I want to change the formula into value but I am getting error.
    The code is:
    Sub Total()
    Range("i8").FormulaR1C1 = _
    "=IF(RC[-2]="""","""",IF(RC[-1]=0,RC[-2],CONCATENATE(RC[-2],""+"",RC[-1])))"
        Range("i8").Copy
                        Range("i9:i100").Select
        ActiveSheet.Paste
                    'Range("i8:i100").Copy
            'Range("i8:i100").PasteSpecial Paste:=xlPasteValues
    Formula = .Value
            MsgBox "Done", 64
    End Sub
    Any help will be appreciated.

    Thanking you.
    Sincerely,

    mso3

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    Sub Total()
    With Range("I8:I100")
        .FormulaR1C1 = _
            "=IF(RC[-2]="""","""",IF(RC[-1]=0,RC[-2],CONCATENATE(RC[-2],""+"",RC[-1])))"
        .Value = .Value
    End With
    MsgBox "Done", 64
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Thank you. It's working fine but still I'm not getting correct output of superscript red code from sheet module.

    Please see the file and solve the problem.

    Thanking you.
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    Strictly speaking, the superscript issue is a different problem. However, the reason it is not working, I think, is because the formula is put into multiple cells. Hence, it seems to me that you can't use the Worksheet Change event handler to format the cells in this instance. The WSC event handler will work if you manually type, for example, 9+10, in a cell which will give you 9+10

    Anyway, the following code seems to do the job:

    Sub APlusB()
    
        Range("F8").FormulaR1C1 = _
            "=IF(COUNTIF(RC[-2]:RC[-1],""AB"")=2,""AB"",IF(SUM(RC[-2]:RC[-1])=0,"""",SUM(RC[-2]:RC[-1])))"
        Range("f8").Copy
                        Range("f9:f100").Select
        ActiveSheet.Paste
                    Range("f8:f100").Copy
            Range("f8:f100").PasteSpecial Paste:=xlPasteValues
            MsgBox "Done", 64
    End Sub
    
    Sub Average()
    Range("g8").FormulaR1C1 = _
                    "=IF(RC[-1]=""AB"",""AB"",IF(RC[-1]="""","""",IF(RC[-1]/2=0,"""",ROUND(RC[-1]/2,0))))"
        Range("g8").Copy
                        Range("g9:g100").Select
        ActiveSheet.Paste
                    Range("g8:g100").Copy
            Range("g8:g100").PasteSpecial Paste:=xlPasteValues
            MsgBox "Done", 64
    End Sub
    
    Sub Total()
    
    Dim cell As Range
    Dim iStart As Integer
    Dim iLength As Integer
    Dim lLR As Long
    Dim rRangeToFormat As Range
    
    lLR = Range("D" & Rows.Count).End(xlUp).Row
    Set rRangeToFormat = Range("I8:I" & lLR)
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    With rRangeToFormat
        .FormulaR1C1 = _
            "=IF(RC[-2]="""","""",IF(RC[-1]=0,RC[-2],CONCATENATE(RC[-2],""+"",RC[-1])))"
        .Value = .Value
    End With
    Application.EnableEvents = True
    
    For Each cell In rRangeToFormat
        If InStr(1, cell, "+") > 0 Then
            iStart = InStr(1, cell, "+")
            iLength = Len(cell) - iStart + 1
            With cell.Characters(Start:=iStart, Length:=iLength).Font
                .Superscript = True
                .ColorIndex = 3
            End With
        Else
            With cell.Font
                .FontStyle = "Regular"
                .Superscript = False
                .ColorIndex = xlAutomatic
            End With
        End If
    Next 'cell
    Application.ScreenUpdating = True
    
    MsgBox "Done", 64
    
    End Sub

    See the updated example workbook.


    Regards, TMS
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Excellent! It's working fine. You have done a great job.

    I appreciate you for your kind cooperation to complete my job.

    Thank you.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    You're welcome. Thanks for the rep.

  7. #7
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    There are headings of columns in row 7 which I don't want to superscript. So I want the code work from row 8. To achieve it I want to insert the code line in the code. I'm confused where to insert the code line to achieve the target. Please tell me where to insert the code line in the code.

    The code line is:

                    If .Row >= 8 Then
    Thank you and sorry for trouble.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    So I want the code work from row 8.
    The code does work from row 8.

    Neither the code that I provided, nor your WSC event handler affect row 7.

    I'm guessing it's just the residual effect of earlier formatting. If you just re-type what you want in row 7 it shouldn't superscript it.

    Regards, TMS

  9. #9
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Sorry for asking the problem here in solved thread again. The problem is related to this thread so I am posting my problem here.

    The superscript problem is solved but I am not getting the correct output in total columns. I am getting output of total column 'I' in other total columns. I am not understanding why it is happening.

    Please see the attachment and give me your valuable guidance to solve this problem.

    Thanking you in anticipation.
    Attached Files Attached Files

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    OK, try it this way:

    Option Explicit
    
    Sub TMS()
    
    'Dim cell As Range
    Dim iStart As Integer
    Dim iLength As Integer
    Dim lLR As Long
    Dim rRangeToFormat As Range
    
    lLR = Range("D" & Rows.Count).End(xlUp).Row
    Set rRangeToFormat = ActiveSheet.Range("I8:I100,O8:O100,u8:u100,aa8:aa100,ag8:ag100,am8:am100,as8:as100,ay8:ay100,be8:be100,bh8:bh100")
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    With rRangeToFormat
        .FormulaR1C1 = _
            "=IF(RC[-2]="""","""",IF(RC[-1]=0,RC[-2],CONCATENATE(RC[-2],""+"",RC[-1])))"
        '.Value = .Value            ' <<< comment this out
    End With
    Application.EnableEvents = True
    
    For Each cell In rRangeToFormat
        cell.Value = cell.Value     ' <<< and add this
        If InStr(1, cell, "+") > 0 Then
            iStart = InStr(1, cell, "+")
            iLength = Len(cell) - iStart + 1
            With cell.Characters(Start:=iStart, Length:=iLength).Font
                .Superscript = True
                .ColorIndex = 3
            End With
        Else
            With cell.Font
                .FontStyle = "Regular"
                .Superscript = False
                .ColorIndex = xlAutomatic
            End With
        End If
    Next 'cell
    Application.ScreenUpdating = True
    
    End Sub

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    Note that you have reverted to fixed ranges going down to row 100. You are not using lLR so you might as well remove the lines:

    Dim lLR As Long

    and:

    lLR = Range("D" & Rows.Count).End(xlUp).Row

  12. #12
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Thank you. It's giving error 'variable not define'.

    I didn't understand the suggestion in post 11. Please guide me.

    Thanking you.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    In the line of code that starts with

    Set rRangeToFormat = ...
    ... you have "& lLR" at the end. Take it out (as I have done)


    Don't worry about post #11. It won't hurt if you leave it as is; you're just not using it. No big deal.

    Regards, TMS

  14. #14
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Thank you.

    Sorry for not understanding your suggestion due to my poor knowledge of vba.

    I'm getting error 'variable not define' on the line

            For Each cell In Range("f8:f100, l8:l100, r8:r100, x8:x100, ad8:ad100, aj8:aj100, ap8:ap100, av8:av100, bb8:bb100")
    on the word 'cell'.

    Please see the macro 'multifunction' for your reference. I have added your new code in it.

    Please do the necessary corrections in the macro 'multifunction' and if possible do send me the modified final copy of workbook.

    Sorry for trouble.

    Thanking you in anticipation.

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,357

    Re: Getting error invalid or unqualified reference

    Example updated ...
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting error invalid or unqualified reference

    Hi TMS,
    Thank you. The problem is solved. If we use 'option explicit' then the problem of 'variable not define' occures.

    Just for knowledge I want to know the best approach to run the various macros one by one?

    1. Integrate the macros in a single macro as we use in the example.
    2. Use call event in this work module and call different macros one by one.

    Thank you very much for your kind cooperation to solve my problems.

    Looking to receive such a valuable guidance in future.

    Thank you and have a nice day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Getting error invalid or unqualified reference
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2014, 02:17 AM
  2. [SOLVED] Getting error invalid or unqualified reference
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2014, 11:31 PM
  3. [SOLVED] Invalid or Unqualified Reference Error
    By Trevasaurus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-28-2013, 11:44 AM
  4. [SOLVED] VBA Debug (compile error invalid or unqualified reference)
    By Kezwick in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 04:38 AM
  5. Invalid or unqualified reference error using the .Find in vba
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2011, 07:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1