Trying to set value of a range equal to IF Statement

ohFice

New Member
Joined
May 30, 2019
Messages
24
Hello,

So I made a column, and placed some formulas in there to provide a number based on other cells.

Within VBA I am trying to set a different range equal to a specific percentage. The percentage would be either 25%, 50% or 75% depending on whether the corresponding amounts in the first range (if larger than 3, 25%, larger than 5, 50%, and larger than 10, is 75%); however, I am currently stuck, and not sure what I am doing wrong. Please see code below.


Code:
[FONT=Verdana]'**Sets Variable For Current Workbook
Dim WorkBook1 As Workbook
    Set WorkBook1 = ThisWorkbook

[/FONT]
[FONT=Verdana]'**Sets Variable For Rent_Roll Sheet
Dim Worksheet1 As Worksheet
    Set Worksheet1 = WorkBook1.Worksheets("Sheet 1")

[/FONT]
[FONT=Verdana]'**Sets Variables For Range to include Percentages
Dim OfficeSC As Range
Dim OfficeRange As Range
    Set OfficeSC = Worksheet1.Range("Q16")
    Set OfficeRange = Range(OfficeSC, OfficeSC.End(xlDown))
    
 '**Sets Variables For Years Column
Dim OfficeYears As Variant
    Set OfficeYears = OfficeRange.Offset(0, 4)
       
'''Runs IF and sets percentages based on years.
If OfficeYears > 10 Then
    OY = 75
ElseIf OfficeYears > 5 Then
    OfficeRange = 50
ElseIf OfficeYears > 3 Then
    OfficeRange = 25
End If[/FONT]

I feel like I'm using the wrong variable type for OfficeYears, but not sure.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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