Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula Copied for Each Date 1

Status
Not open for further replies.

Mizzness

Programmer
May 2, 2003
174
US
All.

By attaching the following code to a button, I'm trying to copy down the formula to the next line. This would bve done on a daily basis.

c3:d3 to c4:d4 one day
c4:d4 to c5:d5 the next and so on.

Sub()
Sheets("P&L Var - MTD Summary").Select
Range("C3:D3").Select
Selection.Copy
Range("C4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Calculate
End Sub

What do I need to add ?

Thanx.
 
Maybe it's solved.

Double click the UserForm control.

This exposes the click even for that control in the VB editor. The upper left dropdown above the code window will show all the control names.The upper right dropdown above the code window will show all the events for the selected control.

To call procedure (macro), you just state the name (and any arguments if there are any)

Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Skip,

You have the patience of a saint.

This is what I have.

Private Sub CommandButton1_Click()
Sub Forest()
End Sub


Private Sub UserForm_Click()

With Sheets("P&L Var - MTD Summary")
r = .[C1].CurrentRegion.Rows.Count
Range(.Cells(r, "C"), .Cells(r, "D")).Copy .Cells(r + 1, "C")
.Calculate
End With
End Sub


I chose UserForm in the name drop box and Click in the control dropbox.

Am I on the right track ?
 

Code:
Private Sub CommandButton1_Click()
  [highlight red]Sub Forest()[/highlight] 'wrong call
  Forest ' correct call
End Sub
Why are you using the UserForm_Click event? Where is your commend button click event???
Code:
Private Sub [highlight red]UserForm_Click()[/highlight]

With Sheets("P&L Var - MTD Summary")
    r = .[C1].CurrentRegion.Rows.Count
    Range(.Cells(r, "C"), .Cells(r, "D")).Copy .Cells(r + 1, "C")
    .Calculate
 End With
End Sub


Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
I guess the simple question here is: How do I call the code set up in the UserFrom to the UserFrom button in my sheet ?

 
better ?

Private Sub CommandButton1_Click()
Forest
End Sub


Private Sub Forest()

With Sheets("P&L Var - MTD Summary")
r = .[C1].CurrentRegion.Rows.Count
Range(.Cells(r, "C"), .Cells(r, "D")).Copy .Cells(r + 1, "C")
.Calculate
End With
End Sub
 

There is no such thing as a "UserFrom button in my sheet"

You either have a Form button on your sheet or a Control Toolbox button on your sheet.

A UserForm is someting yo have to INSERT into your VB Project in the Explorer. You can have a Toolbox Control on a UserForm.

Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
There is no such thing as a "UserFrom button in my sheet" -->
What I meant was a Form Button.

The code posted above in my UserForm, am I on the right track ?
 
Skip,

A star for your time, effort & patience.
Even though I have yet to get it to work, I did learn a thing or two which is what this site is about.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top