Setting Cell as Calculated Value VBA Help

JulieSB

New Member
Joined
Jun 4, 2013
Messages
14
With the code below, I am trying to add two values and then set a cell as that value. Currently this code is putting a 0 in the target cell instead of the two defined values i am trying to add. I have underlined the areas i think are the issue. Any help on why this is not setting the cell to the added value would be appreciated.

Thanks!

Dim DateVal As Date
Dim OffsetVal As Long
Dim NewVal As Integer
Dim LoanVal As Long
Dim d As Long
Dim numDates As Long


Sheets("Balance Sheet Calculations").Select
Range("FirstDate2").Select
numDates = Range(Selection, Selection.End(xlToRight)).Columns.Count 'counts the number of dates


For d = 0 To numDates - 1 'looks at all dates in tab
Sheets("Balance Sheet Calculations").Select
Range("FirstDate2").Offset(0, d).Select 'selects and stores the date - offsets to next date every iteration
DateVal = ActiveCell.Value
OffsetVal = ActiveCell.Offset(10, 0).Value
If OffsetVal > 0 Then
With Range("InterCoIssueDate")
Set c = .Find(DateVal, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, 3) = LoanVal
NewVal = LoanVal + OffsetVal
Set ActiveCell.Value = NewVal
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End If


Next d
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
Do
 c.Offset(0, 3) = LoanVal
 NewVal = LoanVal + OffsetVal
 Set ActiveCell.Value = NewVal
 Loop While Not c Is Nothing And c.Address <> firstAddress
This loop is useless as currently written. When it reads the Loop line, it will exit the Do...Loop because the value of c.Address has not changed. To get it to loop through your 'InterCoIssueDate' range, you need a FindNext statement added in before the Loop line.
Code:
Set c = .FindNext(c)


I don't know why you got a zero value because I cannot see your worksheet to see what the value should be. You can step through the code, using the F8 key, to see what values the range variables contain as the highlight passes over them and initializes them. Just hover the mouse pointer over the variables and the tool tips should show the values. Or you can use the immediate window to monitor the values.
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,684
Members
449,463
Latest member
Jojomen56

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