Setting a variable with a Cells reference

quackdad

Board Regular
Joined
Jul 23, 2013
Messages
110
I'm trying to create a series of macros that determine variables to be used in another macro. The latter macro involves looping through columns, so I'm using a Cells property reference for one of the variables, but when I try to run it I get a Run-time error '1004' (Application-defined or object-defined error). How can I properly set the variable for cond1?

Preliminary macro:
Code:
Dim cond1 As Range
Dim cond2 As Range

Sub Scenario1()
    If Range("E7") = "All" And Range("E5") = "All" Then
        Set cond1 = Cells(13, curCol)
        Set cond2 = Range("E6")
        Application.Run "View"
    End If
End Sub
Target macro:
Code:
Sub View()
    Dim fCell As Range
    Set fCell = Range("I5")
    With Sheets("Employees")
        Do Until fCell.Value = ""
            curCol = fCell.Column
            fCell.Select
            With fCell.EntireColumn
                If cond1 <> cond2 Then
                    .Hidden = True
                Else
                    .Hidden = False
                End If
            End With
            Set fCell = fCell.Offset(0, 1)
        Loop
        Range("B3").Select
    End With
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I jumped the gun on this. I was working with code I'd compiled some time ago, and some crucial lines dropped out when I was truncating it. I see the error of my ways, and the in the question itself. I apologize to the community.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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