Excel/stock

Advertisement


Question
Hi Mr Pieterse

Many thanx for your prompt reply and solution which is working brilliantly

I need some further help here

the stock workbook has 1 to 31 worksheets for each day of the month

I need help with a macro that will be able to copy a column from ws 30 or 31 depending on the mond to a copy of the workbook which be copied


The column would be ws30 / 31 col P

to ws 1 col h of the new file


May I email the file to you for more clarity

KInd regards

Raj

Answer
Hi Raj,

A question first:

Why have a worksheet for each day of the month? It is better to store the data on one single worksheet. That way, making reports (like using pivot tables) is a lot easier.

Later... (having read your email)

This code copies column P of the worksheet belonging to the last day of the month and pasts that column into column H of ws. 1:

Sub CopyPasteLastMonth()
   Dim dDate As Date
   Dim sAnswer As String
   Dim sLastDay As String
   dDate = #1/1/1900#
   sAnswer = InputBox("Please enter the date", , Format(Date, "yyyy/mm/dd"))
   On Error Resume Next
   dDate = CDate(sAnswer)
   If dDate <> #1/1/1900# Then
       'Date entered; proceed
       sLastDay = Day(DateSerial(Year(dDate), Month(dDate) + 1, 0))
       With Worksheets(sLastDay)
         Intersect(.UsedRange.Offset(1), .Range("P:P")).Copy Destination:=Worksheets("1").Range("H2")
       End With
   End If
End Sub

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.