I'm trying to create a vba code that solves this problem: 50 apartment units rent for 600 a month, for each 40 dollar increase in rent a unit becomes unoccupied. I want to find the max profit and number of units at that number.

Sub Rent()
Dim Rent As Variant
Dim increase As Integer
Dim units As Object
Dim Profit As Double
Rent = InputBox("The rent to occupy all the units")
increase = InputBox("The increase in rent that results in a vacant unit")
Rent = Rent + increasea
units = 50
Profit = units * (600 + increase)

Outputbox " " & units & " units and " & Profit & " when profit is maximized."
End Sub

Your code seems to be in reasonable shape, except that it does not yet implement the algorithm to find the maximum revenue.

So the current revenue is 600*50=30,000$ a month.
Your program will increase the rent by $40 steps and recalculate the revenue.
When the revenue starts to decrease, then you have found the maximum revenue.

The programming part will include a for loop for implementing the increase, a method to calculate the new revenue, a variable to keep the old revenue, and an if statement to jump out of the loop when the revenue decreases.

The pseudocode would look something like this:

Define all variables
1. Input current rent (Rent=600$), number of units (Units=50), and critical increase (Increase=40$)
Current revenue (Revenue)=Units*Rent

2. Loop over increases
For inc=40 to Units*40 step40
NewRent=Rent+inc
NewUnits=Units-(inc/40)
NewRevenue=NewRent*NewUnits
If NewRevenue<revenue then exit loop
Revenue=NewRevenue
next inc
Rem: Found max. increase
Output revenue
Output NewUnits-1

If you implement the above pseudocode, you should get the correct result of $1300 as the most profitable rent with a revenue of $42250.

To solve this problem and find the maximum profit along with the corresponding number of units, you would need to iterate through different rent increase values and calculate the profit for each iteration. Here's an updated version of your VBA code that accomplishes this:

```vba
Sub Rent()
Dim Rent As Variant
Dim increase As Integer
Dim units As Integer
Dim maxProfit As Double
Dim maxUnits As Integer

Rent = InputBox("The rent to occupy all the units")
increase = InputBox("The increase in rent that results in a vacant unit")
units = 50

' Initialize the variables for storing maximum profit and units
maxProfit = 0
maxUnits = 0

' Iterate through different rent increase values
For i = 0 To 100 Step increase ' Assuming rent increase can go up to 100

' Calculate the profit for current rent increase and units
Dim currProfit As Double
currProfit = units * (600 + i)

' Check if the current profit is greater than the previous maximum profit
If currProfit > maxProfit Then
maxProfit = currProfit
maxUnits = units
End If

' Decrease the number of occupied units for each 'increase' increment
units = units - 1
Next i

' Display the result
MsgBox maxUnits & " units and " & maxProfit & " when profit is maximized."
End Sub
```

In this code, we use a loop to iterate through different rent increase values from 0 to 100 (you can adjust this range if necessary). For each iteration, we calculate the profit for the current rent increase and units, and then compare it with the previous maximum profit. If it is greater, we update the maximum profit and corresponding number of units. Finally, we display the result using a message box.

Note that in your original code, there was a typo in the line `Rent = Rent + increasea`. It should be `Rent = Rent + increase`. I have corrected it in the updated code.