?
Solved

VB Command Button Macro Help (Posting Months)

Posted on 2012-08-14
4
Medium Priority
?
326 Views
Last Modified: 2012-08-14
HI,

I'm trying to create a Macro that goes to the "Raw Data" sheet and pastes the formula into all of the W:W column and am running into some trouble. I want the formula to go down to the bottom most entry of the last data record entered.

Would someone mind looking at my formula...?

Please and thanks.
SSTempEE.xlsm
0
Comment
Question by:nomios
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 38294125
nomios

If I understand you correctly you need to determine the last cell at runtime to correctly copy down the formula.

To do this use something like

Dim lastrow as long
lastrow = Range("S" & Rows.Count).End(XLup).Row
Range("W2").AutoFill Destination:=Range("W2:W" & lastrow)

Open in new window


Michael
0
 

Author Comment

by:nomios
ID: 38294174
I still can't get it to work....I think I'm doing the code wrong.



    
    Sub PostMonth()
    
            
    
           
       
    Dim lastrow As Long
    lastrow = Range("S" & Rows.Count).End(xlUp).Row
    Range("W2").AutoFill Destination:=Range("V2:V" & lastrow)
    
    Worksheets("Raw Data").Range("V2:V").Formula = "=Month(C2:C)"
    
     SendKeys "{esc}"
    
    
    End Sub
    
    

Open in new window

0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 38294260
nomios

This script will copy down the formula =MONTH(C2) from cell W2 to last used cell in column C

Sub PostMonth()
   Dim lastrow As Long
   
   With Worksheets("Raw Data")
      .Range("W2").Formula = "=MONTH(C2)"
      lastrow = .Range("C" & Rows.Count).End(xlUp).Row
      .Range("W2").AutoFill Destination:=.Range("W2:W" & lastrow)
   End With
 
End Sub

Open in new window


Michael
0
 

Author Closing Comment

by:nomios
ID: 38294314
Worked wonderfully. Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question