Help with changing an existing VBA program

Mike Guest98

New Member
Joined
Jun 4, 2018
Messages
42
I have been using the VBA program on Excel 2010, Windows 7 below but I would like to change it from searching one number to one set of numbers (see my notes below) entered in cell C17. Can this program be used for that purpose? Wondering if someone could look at it and provide any feedback.


Sub do_it()

n = [C17]

For Each cell In Range("B30,E30,H30,K30,N30")
If cell.Value = n And Range(cell.Address).Offset(0, 1) = "1-1" Then
MsgBox "Found a postivive result in " & cell.Address
End If
Next

End Sub

1) Currently the program searches based on what’s entered in cell C17. I would to change the search to cells B30,E30,H30,K30,N30 for any pairs of numbers that has a 15 in the last number, see cell B30 (eg. 8-15). If there is no positive result end the program.

If it finds a 15 two things must happen:

1- The value in the adjacent cell, C30 (2.22) in this example, must be divided by 10 (rounding up) and each amount moved to the following cells: A35,D35,G35,J35,M35,Q35,A39,D39G39,J39,M39,O39. The only issue is the amount divided can not exceed 10.00. The program would divide the 10.00 but anything over that number would be moved via referencing the first number in cell B30 (8) and search the following 10 possible cells: A35,D35,G35,J35,M35,Q35,A39,D39G39,J39,M39,O39 to find 8, in this example, and would find it in cell D39 and the remaining number, if any, would then be ADDED to any number in cell D40 (note: there is an error in my Excel spreadsheet example, cell D40 should not be 2.22).

After this operation there are no contents in cell C30.

2- After a 15 positive result I also need the program to reference the following number in the following 5 cells:

Cell B30 would go to cell B32 so the reference number is 1
Cell E30 would go to cell E32 so the reference number is 2
Cell H30 would go to cell H32 so the reference number is 3
Cell K30 would go to cell K32 so the reference number is 4
Cell N30 would go to cell N32 so the reference number is 5

Using example cell B30 the reference number is 1 so the program would search the range in column D1:D12 for the number 1 and move the set of numbers there and increase the last digit, so it would become 8-16 in cell number E1. After this operation there are no contents in cell B30.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Cross posted https://www.excelguru.ca/forums/showthread.php?9280-Help-with-changing-an-existing-VBA-program

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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