Error with Loop

Jeeremy7

Board Regular
Joined
May 13, 2020
Messages
110
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a problem with one of the loop I'm trying to do and I think it's in the formula but could somoene help me ?
Also I saw that some macro run faster without Loop, is there a way to convert my code without loop ?

Here the code thanks !
VBA Code:
   'Put the total cost plus fee at the end of each code
    Dim A As Long
    Dim B As Integer
    A = ActiveCell.Offset(0, -2)
    B = Sheets("Notes").Range("B1")
    
    Range("K13").Select
    Do Until ActiveCell.Offset(0, -8) = "Total"
        If ActiveCell.Offset(1, -2) = "" Then
            ActiveCell = A * (1 + B)
        Else
            ActiveCell.Offset(1, 0).Select
        End If
    Loop
    
End Sub
 
There is a loop. ;)
It's a For Each loop.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Ok and there's no End If because you take it down all the way up ?
 
Upvote 0
There's no End If, simply because there is no If statement.
 
Upvote 0
How about
VBA Code:
Sub Jeeremy()
   Dim Rng As Range
  
   For Each Rng In Range("J5", Range("J" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.Offset(Rng.Count, 1).Resize(1).FormulaR1C1 = "=rc[-2]*(1+Notes!r1c2)"
   Next Rng
End Sub
Hello Fluff I just realised that when there's just one line the total amount is not there so the macro misses it.
Is there a way to correct that or have some kind of check up so we can't miss it ?

It is row 15-16 on the example

Thanks !
TEST - 1056 - Claim #1 - December 2020.xlsm
ABCDEFGHIJK
1xxxxxxxx
2xxxxxxxx
3
4DateDescriptionSourceJE#AmountCumulative
5xxxxxxxx
6xxxxx
75204xxxxxx
8520411-25-2020xxxxx98J288846,000.0046,000.00
9520411-25-2020xxxxx98 (HB)J2889-6,900.0039,100.00
10520412-25-2020xxxxx106J295951,700.0090,800.00
11520412-25-2020xxxxx106 (HB)J2960-7,755.0083,045.00
12520412-25-2020xxxxx107J296138,722.00121,767.00
135204121,767.00121,767.00
145301xxxxxx
15530112-04-2020xxxxx3206J313117,900.00139,667.00
165302xxxxxx0
17530212-04-2020xxxxx50382678J3089240.00139,907.00
18530212-04-2020xxxxx50382679J30908,550.00148,457.00
1953028,790.008,790.00
205304xxxxxx
21530411-20-2020xxxxx50380789J28917,875.00156,332.00
22530411-20-2020xxxxx50380789 (HB)J2892-1,181.25155,150.75
23530412-17-2020xxxxx50384037J29556,388.00161,538.75
24530412-17-2020xxxxx50384037 (HB)J2956-958.20160,580.55
25530412,123.5512,123.55
266602xxxxxx
27660212-23-2020xxxxx6724J29576,500.00360,828.19
28660212-23-2020xxxxx6724 (HB)J2958-975.00359,853.19
2966025,525.005,525.00
30TOTAL EXPENSE6602166,105.55
31TotalTotal
32-359,853.19
PM TM
 
Upvote 0
What should happen in that situation?
 
Upvote 0
In this case the amont on column K should be the same formula calculated with the single amount.
The formula is supposed to apply on the total but when there's just one amount there's no total line
 
Upvote 0
Should it be on the row below the data or on the same row?
 
Upvote 0
It should be treated as a total so on the same row... Thanks for asking I just realized that right now the 0 value was on the row below
 
Upvote 0

Forum statistics

Threads
1,215,474
Messages
6,125,026
Members
449,204
Latest member
LKN2GO

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