Excel vba increment cell and sheet selection

yinkajewole

Active Member
Joined
Nov 23, 2018
Messages
281
I do run this VBA code

Sub sbCopyRangeToAnotherSheet()


Sheets("Sheet1").Range("B1:I1").Copy Destination:=Sheets("Sheet2").Range("D39:K39")
Sheets("Sheet1").Range("B2:I2").Copy Destination:=Sheets("Sheet3").Range("D39:K39")

End Sub

i.e. changing the range "B1:I1" and sheet "Sheet2" incrementally.

Is there a way the run the code for these portions incrementally without entering the code line by line manually?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It does not change anything if you paste to another sheet. We just don't understand exactly why to try to do. Can you give an example with whatever number so like "User comes on sheet "Data", press a button, comes a message box where he chose between 1 and 16. He types 3 then...

By the way if you want to change i with an input box

Code:
Dim i as variant
i=inputbox("Give me a number between 1-16")
 
Upvote 0
//code
For i = 1 To 15
Sheets("Sheet1").Range("B" & i & ":I" & i).Copy Destination:=Sheets(Format(i + 1, "00")).Range("D39:K39")
Next
 
Upvote 0
Code:
[COLOR=#333333]For i = [B]1[/B] To [B]15[/B][/COLOR]Sheets("[B]Sheet1[/B]").Range("[B]B[/B]" & i & ":[B]I[/B]" & i).Copy Destination:=[B]Sheets(Format(i + 1, "00"))[/B].Range("[B]D39:K39[/B]") [COLOR=#333333]Next[/COLOR]


What I really wanted is that, whenever I should run the code, it should give my an InputBox to put in the above bold numbers, sheet and range
 
Upvote 0
Code:
[COLOR=#333333]For i = [B]1[/B] To [B]15[/B][/COLOR]Sheets("[B]Sheet1[/B]").Range("[B]B[/B]" & i & ":[B]I[/B]" & i).Copy Destination:=[B]Sheets(Format(i + 1, "00"))[/B].Range("[B]D39:K39[/B]") [COLOR=#333333]Next[/COLOR]


What I really wanted is that, whenever I should run the code, it should give my an InputBox to put in the above bold numbers, sheet and range

That is not an input box that you need but a userform...
 
Upvote 0
I started with youtube (https://www.youtube.com/results?search_query=userform+beginner) and googled very specific questions such as "Userform textvalue to cell" when I was blocked.

If too complicated, you can just set up inputbox launched by button (put a few buttons), or a macro launching several inputboxes one after another...but a userform with a few textbox and an ok button is quite easy to set up (unfortunately difficult to explain in a thread).
 
Upvote 0
I started with youtube (https://www.youtube.com/results?search_query=userform+beginner) and googled very specific questions such as "Userform textvalue to cell" when I was blocked.

If too complicated, you can just set up inputbox launched by button (put a few buttons), or a macro launching several inputboxes one after another...but a userform with a few textbox and an ok button is quite easy to set up (unfortunately difficult to explain in a thread).

Code:
[COLOR=#333333]For i = 1 To 15[/COLOR]
[COLOR=#333333]Sheets("...").Range("..." & i & ":..." & i).Copy Destination:=Sheets(Format(i + 1, "00")).Range("....:...")[/COLOR]
[COLOR=#333333]Next[/COLOR]

but i don't seem to find the one that can easily complete some lines of vba code..
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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