Getting the formula in this For loop to include the current column(colnum)

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
917
Office Version
  1. 365
Platform
  1. Windows
This code
Code:
Dim X As Range
   Sheets("Budget").Select
      For i = colnum + 1 To 54
      Cells(30, i).Value = Cells(30, i - 1).Value - Cells(18, i).Value 
      If Cells(30, i) = 0 Then
         MsgBox "Balance is 0 at col  " & i & "  " & "  and week  " & Cells(2, i)
         Range(Cells(30, i + 1), Cells(30, 54)).ClearContents
         Exit For
      End If                                                           
     Next
     End Sub
works perfectly for every column AFTER colnum. When I change this line
Code:
 For i = colnum + 1 To 54
to
Code:
 For i = colnum  To 54
the calculation
Code:
 Cells(30, i).Value = Cells(30, i - 1).Value - Cells(18, i).Value
does not calculate correctly. It is something very simple I haven't been able to figure out yet.
That is, to use For i = colnum To 54 and have the formula calculate the correct balances on the current (colnum) and each successive cell column.
It's been a struggle. Can anyone help me with the correct formula that will include colnum
and not start the For loop at colnum +1 to have it come out right ?

Tried to keep it simple, but complete.

Thanks for anyone's help.
cr
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You haven't declared colnum ?
AND what is colnum set to in the first instance ?
 
Upvote 0
You haven't declared colnum ?
AND what is colnum set to in the first instance ?

Colnum is a function in a module that varies with time. This should be self explanatory:
Code:
Function colnum()
colnum = Round((Date - DateValue("12/19/2018")) / 7, 0)
'MsgBox colnum
End Function
Very simply, as weeks change throughout the year, so does the value of colnum. To me, this has nothing to do with my
issue - the problem is in the calculation in the For loop formula I created.
cr
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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