Increasing value in cell and copying results into list a fixed amount of times (VBA issue)

jspedt

New Member
Joined
Mar 15, 2021
Messages
4
Office Version
  1. 2007
Platform
  1. Windows
Hi everyone,

I have looked at the threads and cannot seem to find an answer to my issue despite it likely being a very simple code.

Bear with me for potential clarification, as I have not used VBA at all.

What I am trying to do (I have attached a picture for clarification):

The starting variable is K27. I want to change this in 50 increments and copy and paste the changes in values accordingly.

So starting at a 100 I want to:
K27 Input 100
Copy O36, paste into F48
Copy P47, paste into G48
Copy K27, paste into B48

Return and increase K27 to 150 (i.e. 100+50)
Copy O36, paste into F49 (now moved down 1 row)
Copy P47, paste into G49
Copy K27, paste into B49

And then run this loop x amount of times so I can adjust how much I want to increase K27 with.

The intend is to have a list so that I can see how the K27 input impacts the overall output.

I really hope you can help, as it would save a lot of manual work.

Thanks in advance
 

Attachments

  • VBA Question.PNG
    VBA Question.PNG
    117.9 KB · Views: 14

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You should have used XL2BB to select the range of your excel to be copied and paste. Otherwise it will be time consuming to recreate your sheet and test the code. Furthermore, we cannot see any formula to see how the numbers come about.

You said Copy P47, paste into G48. Is it P49?

Anyway, are you familiar with ActiveX button, TextBox etc. and how to attach VBA code to it?
 
Upvote 0
Here is the code which I think should work. Not able to fully test.

Here is how it is suppose to run as I tested it
1) Create an ActiveX TextBox on the sheet.
2) Create a Command button, label it as OK and attach the code to it to run upon click

In the TextBox, just key in how many iteration you like. Then click OK. If you do not erase the result, it will keep adding to the list.

Let me know if you encounter problem.

VBA Code:
Private Sub CommandButton1_Click()

If TextBox1 = "" Then Exit Sub
rowB = 0

For i = 1 To TextBox1.Value
    If Len(Range("B48")) = 0 Then
        Range("K27") = 100
        Range("B48") = Range("K27")
        Range("F48") = Range("O36")
        Range("G48") = Range("P49")
    Else
        If rowB = 0 Then rowB = Range("B" & Rows.Count).End(xlUp).Row
        rowB = rowB + 1
        Range("K27") = 100 + (i * 50)
        Range("B" & rowB) = Range("K27")
        Range("F" & rowB) = Range("O36")
        Range("G" & rowB) = Range("P49")
    End If
Next

End Sub
 
Upvote 0
Solution
Hi Zot,

Thank you for the response.

Sorry for the lack of information, but regardless, the code worked perfectly - thanks a lot!

One other thing, would you know how I could edit the code to paste the values as percentages? Naturally, it is easy to convert manually, but it would be neat to have the code doing that automatically.

Again, thanks for the response!
 
Upvote 0
Hi Zot,

Thank you for the response.

Sorry for the lack of information, but regardless, the code worked perfectly - thanks a lot!

One other thing, would you know how I could edit the code to paste the values as percentages? Naturally, it is easy to convert manually, but it would be neat to have the code doing that automatically.

Again, thanks for the response!
You need to change at two places
1) Range("G48") = Range("P49")
2) Range("G" & rowB) = Range("P49")

= Range("P49") change to = Format(Range("P49"), "Percent")
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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