[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Running Two Macros as One

cheeser83

12/19/2006 5:53:00 PM

I have to Macros. The first one will copy data from one sheet and
paste it to another. The second one will then change the data in
certain cells to the proper Month Name.

What I would like to do is have one macro for each month. After it
inputs the proper month name, it then runs the copy and paste macro.
Is there a way to do this???

Any help is MUCH appreciated!

3 Answers

cheeser83

12/19/2006 6:15:00 PM

0

First Module:

Public Sub CopyPaste()

'
Sheets("Forecast Report").Select 'Copies Total Yards from
currenct Forecast and pastes
Range("E105").Select 'to LST FRCST PRDCT
Total for the new Forecast Report
Selection.Copy
Range("AL105").PasteSpecial xlPasteValues




End Sub

Second Module:

Sheets("Worksheet").Select
'Pastes "January" in Month headers
Range("B4").Select
ActiveCell.FormulaR1C1 = "January"
With ActiveCell.Characters(Start:=1, Length:=7).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
End With
Sheets("Forecast Report").Select
Range("B3").Select
ActiveCell.FormulaR1C1 = "January"
With ActiveCell.Characters(Start:=1, Length:=7).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 2
End With
Range("B4:B6").Select
End Sub

I need to run one module and then the other. The order doesn't matter.
However, I will have 12 modules similar to module 2, one for each
month. I don't want to just paste the code from module 1 into two
because I will be adding to it later.
Jim Thomlinson wrote:
> Post your code...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "cheeser83" wrote:
>
> > I have to Macros. The first one will copy data from one sheet and
> > paste it to another. The second one will then change the data in
> > certain cells to the proper Month Name.
> >
> > What I would like to do is have one macro for each month. After it
> > inputs the proper month name, it then runs the copy and paste macro.
> > Is there a way to do this???
> >
> > Any help is MUCH appreciated!
> >
> >

Jim Thomlinson

12/19/2006 6:57:00 PM

0

Try this... Your code can be really shortened up a whole pile...

Public Sub CopyPaste()
With Sheets("Forecast Report")
.Range("AL105").Value = .Range("E105").Value
End With
End Sub

Second Module:

'Pastes "January" in Month headers
With Sheets("Worksheet").Range("B4")
.Value = "January"
.Font.FontStyle = "Bold"
.Font.ColorIndex = 2
End With
With Sheets("Forecast Report").Range("B3").
.Value = "January"
.Font.FontStyle = "Bold"
.Font.ColorIndex = 2
End With
Sheets("Forecast Report").Range("B4:B6").Select
Call CopyPaste 'Call the CopyPaste Routine
End Sub

--
HTH...

Jim Thomlinson


"cheeser83" wrote:

> First Module:
>
> Public Sub CopyPaste()
>
> '
> Sheets("Forecast Report").Select 'Copies Total Yards from
> currenct Forecast and pastes
> Range("E105").Select 'to LST FRCST PRDCT
> Total for the new Forecast Report
> Selection.Copy
> Range("AL105").PasteSpecial xlPasteValues
>
>
>
>
> End Sub
>
> Second Module:
>
> Sheets("Worksheet").Select
> 'Pastes "January" in Month headers
> Range("B4").Select
> ActiveCell.FormulaR1C1 = "January"
> With ActiveCell.Characters(Start:=1, Length:=7).Font
> .Name = "Arial"
> .FontStyle = "Bold"
> .Size = 10
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleNone
> .ColorIndex = 2
> End With
> Sheets("Forecast Report").Select
> Range("B3").Select
> ActiveCell.FormulaR1C1 = "January"
> With ActiveCell.Characters(Start:=1, Length:=7).Font
> .Name = "Arial"
> .FontStyle = "Bold"
> .Size = 10
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleNone
> .ColorIndex = 2
> End With
> Range("B4:B6").Select
> End Sub
>
> I need to run one module and then the other. The order doesn't matter.
> However, I will have 12 modules similar to module 2, one for each
> month. I don't want to just paste the code from module 1 into two
> because I will be adding to it later.
> Jim Thomlinson wrote:
> > Post your code...
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "cheeser83" wrote:
> >
> > > I have to Macros. The first one will copy data from one sheet and
> > > paste it to another. The second one will then change the data in
> > > certain cells to the proper Month Name.
> > >
> > > What I would like to do is have one macro for each month. After it
> > > inputs the proper month name, it then runs the copy and paste macro.
> > > Is there a way to do this???
> > >
> > > Any help is MUCH appreciated!
> > >
> > >
>
>

cheeser83

12/19/2006 7:14:00 PM

0

Thank You! I figured out what I was doing wrong in the second module
with your help with it. I was not putting the Call CopyPaste within
the same Sub routine.

As far as shortening my code goes, I will try that out also. Thank you
for the help!

Jim Thomlinson wrote:
> Try this... Your code can be really shortened up a whole pile...
>
> Public Sub CopyPaste()
> With Sheets("Forecast Report")
> .Range("AL105").Value = .Range("E105").Value
> End With
> End Sub
>
> Second Module:
>
> 'Pastes "January" in Month headers
> With Sheets("Worksheet").Range("B4")
> .Value = "January"
> .Font.FontStyle = "Bold"
> .Font.ColorIndex = 2
> End With
> With Sheets("Forecast Report").Range("B3").
> .Value = "January"
> .Font.FontStyle = "Bold"
> .Font.ColorIndex = 2
> End With
> Sheets("Forecast Report").Range("B4:B6").Select
> Call CopyPaste 'Call the CopyPaste Routine
> End Sub
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "cheeser83" wrote:
>
> > First Module:
> >
> > Public Sub CopyPaste()
> >
> > '
> > Sheets("Forecast Report").Select 'Copies Total Yards from
> > currenct Forecast and pastes
> > Range("E105").Select 'to LST FRCST PRDCT
> > Total for the new Forecast Report
> > Selection.Copy
> > Range("AL105").PasteSpecial xlPasteValues
> >
> >
> >
> >
> > End Sub
> >
> > Second Module:
> >
> > Sheets("Worksheet").Select
> > 'Pastes "January" in Month headers
> > Range("B4").Select
> > ActiveCell.FormulaR1C1 = "January"
> > With ActiveCell.Characters(Start:=1, Length:=7).Font
> > .Name = "Arial"
> > .FontStyle = "Bold"
> > .Size = 10
> > .Strikethrough = False
> > .Superscript = False
> > .Subscript = False
> > .OutlineFont = False
> > .Shadow = False
> > .Underline = xlUnderlineStyleNone
> > .ColorIndex = 2
> > End With
> > Sheets("Forecast Report").Select
> > Range("B3").Select
> > ActiveCell.FormulaR1C1 = "January"
> > With ActiveCell.Characters(Start:=1, Length:=7).Font
> > .Name = "Arial"
> > .FontStyle = "Bold"
> > .Size = 10
> > .Strikethrough = False
> > .Superscript = False
> > .Subscript = False
> > .OutlineFont = False
> > .Shadow = False
> > .Underline = xlUnderlineStyleNone
> > .ColorIndex = 2
> > End With
> > Range("B4:B6").Select
> > End Sub
> >
> > I need to run one module and then the other. The order doesn't matter.
> > However, I will have 12 modules similar to module 2, one for each
> > month. I don't want to just paste the code from module 1 into two
> > because I will be adding to it later.
> > Jim Thomlinson wrote:
> > > Post your code...
> > > --
> > > HTH...
> > >
> > > Jim Thomlinson
> > >
> > >
> > > "cheeser83" wrote:
> > >
> > > > I have to Macros. The first one will copy data from one sheet and
> > > > paste it to another. The second one will then change the data in
> > > > certain cells to the proper Month Name.
> > > >
> > > > What I would like to do is have one macro for each month. After it
> > > > inputs the proper month name, it then runs the copy and paste macro.
> > > > Is there a way to do this???
> > > >
> > > > Any help is MUCH appreciated!
> > > >
> > > >
> >
> >