Script needed

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello ,

I need a script for some task:

I have a list of items in a range say A2:A50. I need a script that when I run it, it will change the cell B2 to the value in A2 then A3 in that order till I get to the last cell in the range A2:A50 that has no value. The cells don't have any formulas.

I need this script because I will use it for printing a sheet and the data on the sheet is determined by the value in B2 . So I need a script that can help me take care of take.


So after changing the cell value in B2 to the content in A2, I call my print macro then change the value to the content of A3 then call my macro again in that order.

Thank you in advance
Kelly
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
something like:

Code:
Sub LoopIt()

Dim rng As Range
Dim r As Long
Set rng = ActiveSheet.Range("A2")

r = 0
Do While rng.Offset(r, 0) <> ""
    Range("B2") = rng.Offset(r, 0)
    
    ' call your printing routine here

    r = r + 1
Loop
End Sub
 
Upvote 0
Try this:-
Each Time you run the code the value in "B2" will change
Code:
Option Explicit
[COLOR="Navy"]Dim[/COLOR] rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Sub[/COLOR] Newname()
[COLOR="Navy"]If[/COLOR] rng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] rng = Range("A2")
    Range("B2") = rng
    [COLOR="Navy"]Set[/COLOR] rng = rng.Offset(1)
[COLOR="Navy"]If[/COLOR] rng = "" [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] rng = Range("A2")
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Wow. Faster than I thought. Thanks to you all for the great assistance. I am grateful.

Both codes worked just fine.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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