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
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

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
 

Watch MrExcel Video

Forum statistics

Threads
1,114,676
Messages
5,549,371
Members
410,911
Latest member
AniEx
Top