Macro to Copy Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,568
Office Version
  1. 2021
Platform
  1. Windows
I have the following Data Below

I have code to copy the Data in Col F and to paste value these in Col C from row 3 onwards, except where the data contains = sum formula (this must be left intact

When running the formula the the opening bal should equal the closing bal before the macro was run

Code:
 Sub Copy_Closing_Balances()
Sheets("sheet1").Select
Dim lr As Integer, Lr1 As Integer

lr = Range("F3").End(xlDown).Row

    For I = 3 To lr
        If Left(Range("F" & I).Formula, 4) = "=SUM" Then
                Else
            Range("C" & I).Value = Range("f" & I).Value
        End If
    Next I
Lr1 = Range("F16").End(xlDown).Row

    For J = 3 To Lr1
        If Left(Range("F" & J).Formula, 4) = "=SUM" Then
                Else
            Range("C" & J).Value = Range("f" & J).Value
        End If
    Next J
End Sub


This is what the openiing balances look like after running the macro

your assistance in resolving this is miost appreciated

Excel Workbook
ABCDEF
1
2DescriptionAccount NumberOpening Balance CostPurchasesDisposalsClosing Balance Cost
3Corporate Signage455137020,311.008,834.000.0029,145.00
4Furniture and Fittings455132010,270.384,754.200.0015,024.58
5Generators45513500.000.000.000.00
6Office Equipment45513302,101.650.000.002,101.65
7Plant and Machinery455131010,875.023,940.270.0014,815.29
8Computer Equipment45513400.000.000.000.00
9Small Tools45513800.000.000.000.00
10
11Total43,558.0517,528.470.0061,086.52
12
13
14
15DescriptionAccount NumberAcc DeprCurrent Year DeprDisposalsAcc Depr
16Corporate Signage45514703,133.14490.140.003,623.29
17Furniture and Fittings45514201,158.16396.180.001,554.34
18Generators45514500.000.000.000.00
19Office Equipment45514302,101.650.000.002,101.65
20Plant and Machinery45514102,599.68613.870.003,213.56
21Computer Equipment45514400.000.000.000.00
22Small Tools45514800.000.000.000.00
23
24Total8,992.641,500.200.0010,492.84
25
26
27
Sheet1
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Sample Data before running Macro


Excel 2012
ABCDEF
1Per Asset RegisterUpdated on: 17/11/2014 18:16
2DescriptionAccount NumberOpening Balance CostPurchasesDisposalsClosing Balance Cost
3Corporate Signage45513702,643.008,834.000.0011,477.00
4Furniture and Fittings4551320761.984,754.200.005,516.18
5Generators45513500.000.000.000.00
6Office Equipment45513302,101.650.000.002,101.65
7Plant and Machinery45513102,994.493,940.270.006,934.76
8Computer Equipment45513400.000.000.000.00
9Small Tools45513800.000.000.000.00
10
11Total8,501.1217,528.470.0026,029.59
12
13
140
15DescriptionAccount NumberAcc DeprCurrent Year DeprDisposalsAcc Depr
16Corporate Signage45514702,643.00490.140.003,133.14
17Furniture and Fittings4551420761.98396.180.001,158.16
18Generators45514500.000.000.000.00
19Office Equipment45514302,101.650.000.002,101.65
20Plant and Machinery45514101,985.81613.870.002,599.68
21Computer Equipment45514400.000.000.000.00
22Small Tools45514800.000.000.000.00
23
24Total7,492.441,500.200.008,992.64
25
26
27
Sheet1


Sample Data after Running Macro


Excel 2012
ABCDEFG
1Per Asset RegisterUpdated on: 17/11/2014 18:19
2DescriptionAccount NumberOpening Balance CostPurchasesDisposalsClosing Balance Cost
3Corporate Signage455137020,311.008,834.000.0029,145.00
4Furniture and Fittings455132010,270.384,754.200.0015,024.58
5Generators45513500.000.000.000.00
6Office Equipment45513302,101.650.000.002,101.65
7Plant and Machinery455131010,875.023,940.270.0014,815.29
8Computer Equipment45513400.000.000.000.00
9Small Tools45513800.000.000.000.00
10
11Total43,558.0517,528.470.0061,086.52
12
13
140
15DescriptionAccount NumberAcc DeprCurrent Year DeprDisposalsAcc Depr
16Corporate Signage45514703,133.14490.140.003,623.29
17Furniture and Fittings45514201,158.16396.180.001,554.34
18Generators45514500.000.000.000.00
19Office Equipment45514302,101.650.000.002,101.65
20Plant and Machinery45514102,599.68613.870.003,213.56
21Computer Equipment45514400.000.000.000.00
22Small Tools45514800.000.000.000.00
23
24Total8,992.641,500.200.0010,492.84
25
26
Sheet1


Look at row 3 Corporate signage-the closing balance was R 11,477.00 -after running the macro the opening bal for corporate signage should be R 11477. but instead the opening bal shows is 20311

It would be appreciated if you could assist in resolving this
 
Last edited:
Upvote 0
Your macro effectively runs twice ..... you have 2 for loops that do essentially the same and so the first loop copies the closing balance to the opening balance ... the closing balance is then updated by its own formula and then the 2nd loop copies it to the opening balance again.

Check the first row numbers and you'll see what I mean
 
Upvote 0

Forum statistics

Threads
1,215,781
Messages
6,126,869
Members
449,345
Latest member
CharlieDP

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