Compile error

jyokom

Board Regular
Joined
May 24, 2004
Messages
148
Why do I get a compile error: Invalid Qualifier when I run the following? The debugger highlights the "i" in the line Cbo_ARTrack & i.Value

Sub SaveAR_Loop()
Dim i As Integer
Dim NextRow As Integer
NextRow = Worksheets("Saved").Range("A65536").End(xlUp).Row + 1
For i = 1 To 8
Worksheets("Saved").Cells(NextRow, 14 + i).Value = "Cbo_ARTrack" & i.Value
Worksheets("Saved").Cells(NextRow, 15 + i).Value = "DTP_ARCT" & i.Value
Worksheets("Saved").Cells(NextRow, 16 + i).Value = "TB_TrkTime" & i.Value
Worksheets("Saved").Cells(NextRow, 17 + i).Value = "Cbo_RcvrUnit1_" & i.Value
Worksheets("Saved").Cells(NextRow, 18 + i).Value = "Cbo_RcvrMDS1_" & i.Value
Worksheets("Saved").Cells(NextRow, 19 + i).Value = "TB_RcvrCall1_" & i.Value
Worksheets("Saved").Cells(NextRow, 20 + i).Value = "TB_OffOn1_" & i.Value

Next i

ThisWorkbook.Save

End Sub
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You use .Value on a Range or other objects, i is just a number...

Change all the
i.Value
to just
i

hope that helps.
 
Upvote 0
You need to take the .Value of from the i.

Code:
Worksheets("Saved").Cells(NextRow, 14 + i).Value = Cbo_ARTrack & i

You just use i on its own as it is an integer value.
 
Upvote 0
Actually each of those are controls. and aren't returning the values of the controls. The controls are named for example Cbo_ARTrack1 & Cbo_ARTrack2, etc.
 
Last edited:
Upvote 0
Unfortunately, it's much more difficult to loop through controls than you would think...

Standby...
 
Upvote 0
See if this gets you started...

Code:
Sub testing()
Dim c As OLEObject, x As Long, NextRow As Long
NextRow = Worksheets("Saved").Range("A65536").End(xlUp).Row + 1
For Each c In Sheets("Saved").OLEObjects
    Select Case Left(c.Name, Len(c.Name) - 1)
        Case "Cbo_ARTrack": x = 14
        Case "DTP_ARCT": x = 15
        Case "TB_TrkTime": x = 16
        Case "Cbo_RcvrUnit1_": x = 17
        Case "Cbo_RcvrMDS1_": x = 18
        Case "TB_RcvrCall1_": x = 19
        Case "TB_OffOn1_": x = 20
        Case "TextBox": x = 21
    End Select
    Worksheets("Saved").Cells(NextRow, x + Right(c.Name, 1)).Value = c.Object
Next c
End Sub
 
Upvote 0
Wait, this might be better and easier to follow/modify

Code:
Sub testing()
Dim i As Long, NextRow As Long
NextRow = Worksheets("Saved").Range("A65536").End(xlUp).Row + 1
With Sheets("Sheet1")
    For i = 1 To 8
        .Cells(NextRow, 14 + i).Value = .OLEObjects("Cbo_ARTrack" & i).Value
        .Cells(NextRow, 15 + i).Value = .OLEObjects("DTP_ARCT" & i).Value
        .Cells(NextRow, 16 + i).Value = .OLEObjects("TB_TrkTime" & i).Value
        .Cells(NextRow, 17 + i).Value = .OLEObjects("Cbo_RcvrUnit1_" & i).Value
        .Cells(NextRow, 18 + i).Value = .OLEObjects("Cbo_RcvrMDS1_" & i).Value
        .Cells(NextRow, 19 + i).Value = .OLEObjects("TB_RcvrCall1_" & i).Value
        .Cells(NextRow, 20 + i).Value = .OLEObjects("TB_OffOn1_" & i).Value
    Next i
End With
ThisWorkbook.Save
End Sub
 
Upvote 0
I get a compile error: Invalid or unqualified reference with the first .OLEObjects selected
 
Upvote 0
In the VBA window, go to tools - references
Make sure you have the following checked..

Visual Basic For Applications
Microsoft Excel xx.x Object Library
OLE Automation
Microsoft Office xx.x Object Library

Save/Close/Reopen.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,314
Members
452,905
Latest member
deadwings

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