'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
 
I mean they are not empty. Blank and empty are two different things.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You can upload to a share site such as OneDrive, Google Drive or DropBox, mark for sharing & post the link you are given to the thread.
 
Upvote 0
You can upload to a share site such as OneDrive, Google Drive or DropBox, mark for sharing & post the link you are given to the thread.
Ok. Let me try Google Drive. I had done that a long ago. Will share the link.
 
Upvote 0
Fluff, Please check this link. I hope I have done it right. If not working, let me know. Will try again.
I haven't run the new macro 'Match' in this sheet. This is the macro that does need editing. All the other macros are running perfectly. Press the button 'Clear workings' to run the macro again.
 
Upvote 0
After running all the macros, the final result is perfect. I don’t want the daily cash to be the same on all days. So, I was trying to cut 2 cells from the end and replace them in other columns in the beginning without changing the total sum of daily. That is the 'Match' macro for.
 
Upvote 0
The only problem is that you haven't change the range, your data is going down to about row 620, not row 16
 
Upvote 0
The only problem is that you haven't change the range, your data is going down to about row 620, not row 16
I replaced 16 with 619. What do I write in place of -14 ? Does the whole code need to be edited ?
 
Upvote 0
Got it right Fluff. Thanks once again.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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