'for' Loop

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,

I am trying to do something new. With the help of a VBA code, in every case, last 2 Values of last 2 cells of columns D-15 to D-28 to be cut and pasted to Columns D-1 to D-14 in the next empty cell, with the help of a code. There are 2 sheets in the workbook. One is the original and the other is the expected result after the code is run.

I am not even sure how it is possible to cut the values using a VBA code. I just need a “for” loop to get the cell values from columns 15-28 to the corresponding 1-14. Finally, the sum total value of A17:AB17 should not change after the code is run. Something like lRow = Cells(16,lColNo ).End(xlUp).Row.value = value.
This is the raw sheet
Query Random Sort cut paste with the help of code.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
212345678910111213141512345678910111213
32345678910111213141516234567891011121314
434568910111213141516173456789101112131415
5456791112141618456789111213141516
6567810121315567891012131516
7791479101417
8810158101115
99111691116
1010171017
1111181118
1212191219
13
14
15
16
171577256011402450154336539584566157725605640245015446658758
181519
19
Original
Cell Formulas
RangeFormula
A17:AB17B17=SUM(B2:B16)
A18A18=SUM(A17:AB17)


and this is the expected answer after the code is run

Query Random Sort cut paste with the help of code.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1D-1D-2D-3D-4D-5D-6D-7D-8D-9D-10D-11D-12D-13D-14D-15D-16D-17D-18D-19D-20D-21D-22D-23D-24D-25D-26D-27D-28
212345678910111213141512345678910111213
3234567891011121314151623456791011121314
434568891011121314151634567810111314
54567999111218141416155671215
6567810101213191515161667813
717711981412177914
818812109151381015
99111691116
101010171017
11111118
121219
13411
14512
15
1650864881284043671777090689176316542560182172711721365427
171519
181519
190Differnce must be 0
After Code
Cell Formulas
RangeFormula
A16:AB16B16=SUM(B2:B15)
A17A17=SUM(A16:AB16)
A18A18=Original!A18
A19A19=A17-A18
 
Do you have formulae in those cells?
 
Upvote 0

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
Do you have formulae in those cells?
In the last 3 rows Yes. One is the sum total of each column, one is a formula taken from a different sheet to get the exact match and the third is the difference of the above 2. Also the headings are derived from a formula
 
Upvote 0
But not in the cells you want moving?
 
Upvote 0
Were there formulae in there that you have copy/pasted as values?
 
Upvote 0
Were there formulae in there that you have copy/pasted as values?
The values are derived from a different code and are posted in this sheet. But without any formula.
 
Upvote 0
If it's always pulling from rows 15/16 & pasting into 1/2, then the blank cells are not empty, which is why the code does not work.
You will need to revisit the code that populates the cells
 
Upvote 0
If it's always pulling from rows 15/16 & pasting into 1/2, then the blank cells are not empty, which is why the code does not work.
You will need to revisit the code that populates the cells
It should pull the values of the last 2 cells in columns O to AD and paste it in the cells in the last empty cells of columns A to N. So that the total sum in the last doesn't change. This is what I am expecting.
 
Upvote 0
I know what you are expecting. But the code will not work if the "blank" cells are not empty.
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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