Macro for a selected data

bombur10

New Member
Joined
Sep 21, 2006
Messages
4
Hi, I want to run a macro where I want to be able to see a certain range of data in a print preview. My problem is, let's say I move the data over somewhere else, I want the macro to follow the data and not stay at the previous range. Does that make sense? Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
Hi -
Welcome to the board.
try this;
Select the range > Insert > Name > define and named it as "test"
then write a macro like this;
Code:
sub followdata()
range("test").printpreview
End Sub
 

bombur10

New Member
Joined
Sep 21, 2006
Messages
4
what happens if the area of data I want to select are from two separate places. How can I select the stuff I want to see in print preview? Thanks
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
select the first cell, hold Ctrl key then select the other cell, then define the name as previously instructed, then run this code;

Code:
Sub followdata()
Range("test").Select
ActiveWindow.SelectedSheets.PrintPreview
End Sub
 

bombur10

New Member
Joined
Sep 21, 2006
Messages
4
Well if I record a macro, it gives me this:
Sub Macro5()
'
' Macro5 Macro
Macro recorded 9/21/2006 by xxx

How do I put your part in afterwards without the sub part? It won't let me do it twice. Thanks
 

bombur10

New Member
Joined
Sep 21, 2006
Messages
4
Okay I think I'm supposed to find the region that I defined. So if I defined a region and called it ("Test"), how do I select the region and make it my currentregion? This way if I move the data ("Test"), I still want to print preview the data and not the wrong region. Thanks people
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,129
Messages
5,857,537
Members
431,884
Latest member
Gcmoore63

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
Top