copy date to another workbook's month tab and day cell

Dukman83

New Member
Joined
Jun 10, 2011
Messages
5
Hi guys, I was wondering if anyone can help me with a massive issue i'm experiencing with excel vba at the moment.

What I am trying to do is select one cell only in an invoice workbook called "Invoices Template" and determine the date that is within that cell. Once the date is determined, I would like it to copy the cell with the invoice fee and select the date's respective month worksheet, and paste it into it's respective date cell in a different workbook called "Balance Sheets". For example, the date on the invoice may be 20/09/10 (DD/MM/YY format). It would copy the invoice fee and paste it into the "Balance Sheets" "September" tab, into a cell that is designated the date of 20.

I honestly don't even know where to begin with this.
I have been trying to nut this out for a few solid days and have not been able to make it work for me,
Any help will be greatly appreciated.
P.S. Please let me know if you'd like any code specifics.
Cheers,
Alex
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi there,
some code might indeed help a little... But to get you started:
You could in VBA use a formula like Month(YourDate) to determine the month, Day(YourDate) to determine the day. With the found month you probably want to look up the name of the sheet (as in: if you find "9", you'll have to "translate" that to "september")
For more specific help, I'll need some code/background.

Cheers,
Koen
 
Upvote 0
Hi guys, I was wondering if anyone can help me with a massive issue i'm experiencing with excel vba at the moment.

What I am trying to do is select one cell only in an invoice workbook called "Invoices Template" and determine the date that is within that cell. Once the date is determined, I would like it to copy the cell with the invoice fee and select the date's respective month worksheet, and paste it into it's respective date cell in a different workbook called "Balance Sheets". For example, the date on the invoice may be 20/09/10 (DD/MM/YY format). It would copy the invoice fee and paste it into the "Balance Sheets" "September" tab, into a cell that is designated the date of 20.

I honestly don't even know where to begin with this.
I have been trying to nut this out for a few solid days and have not been able to make it work for me,
Any help will be greatly appreciated.
P.S. Please let me know if you'd like any code specifics.
Cheers,
Alex

Alex welcome to the Forum,

As suggested you would need to determin the month and day from the date. Shown here is a small sample that will work out the month and day and print them to the Immediate window. Give this a go to get you thinking and post back.

Open a New workbook, then use ALt + F11 (takes you into VBA), then select the Insert Menu and Module and also the Immediate window. Copy and paste this code then stay in the code and press F5 the immediate window will display the results.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> dateMonth()<br>Debug.Print Month("21/06/2011")<br>Debug.Print Day("21/06/2011")<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Thanks for all your help guys!

Trevor,
I have opened a new workbook and inserted a new module and copied the code into the main window, ran it and it didn't actually do anything?
I was scratching my head for ages trying to work out if i did anything wrong, but wasn't able to replicate your soultion, any hints?

Koen,
The code implements a whole lot of other functions which will massively clutter the forum, so the background might be ideal in this circumstance, seeing as I'm not sure if I can upload the workbook for viewing.

The workbook is called Invoices Template, which automatically opens the workbook Balance Sheets and another workbook to copy various bits of invoicing data.
So the Invoices Template is the actual invoice with various bits of information such as the invoice sum, the date of the invoice creation, services offered etc..
The relevant cells are cell D18, which has the date of the invoice creation entered in it and H33, which has the value which needs to be copied to the relevant cell in the new workbook (Balance Sheets). Balance Sheets has tabs (worksheets) named by their relevant month names (January-December).
So if the date entered in D18 is 20/09/10, the invoice value in H33 needs to be copied to the workbook "Balance Sheets" worksheet September, and to a cell range between B4:P4 and B22:Q22(day 1 to 15 and 16 to 31). In this case it falls into the cell F22(20'th day).

I hope this makes sense, otherwise I CAN try to copy the code, but I'm not sure if it would make any sense without the workbook data?

Thanks again guys, you are really helping me with this, I REALLY appreciate your help!

Cheers,

Alex
 
Upvote 0
Alex sorry for delay in replying (work commitments). When you added the code into the VBA screen did you also show the Immediate Window from the View Menu). The immedaite window is a testing area rather than running direct from/to a workbook/worksheet. My thoughts were to see if you could recognise the month and day as a number.
 
Upvote 0
Thanks for getting back to me Trevor.

I have to admit i never even knew the "Immediate window" existed.
It looks like a brilliant tool even though I'm not fully aware of it's full function.

I have tried the formula and noticed how it prints the month and day however am not able to go further with this. I have tried to use the "IF" statements to print a message box IF the month is 'XX' but with no luck.

I have to say that although I have played a fair bit with excel vba, I am still very much a beginner and there is still a lot i don't know about programming.

Even if I get this function to working, I'm not sure it's viable because I'd have to have several lines of code including "IF" statements for every month tab and every day cell to copy the value to.

I have searched very broadly for anything close to what I need to make this work and the closest possible function is listed below. It is from http://stackoverflow.com/questions/...opy-rows-to-another-worksheet/6167187#6167187
However it uses sharepoint, which I have no idea of, but this is the model I tried to modify to do what I need to do, and again with no luck.

Below that I have pasted what I thought would be a working model of what I need, again with no luck.

I'm so far lost for even knowing where to look for information or where to begin learning this that I don't know what to do.

I say again, I really appreciate your help because I feel hopelessly lost with this.


<code>Public Sub MoveData(MonthNumber As Integer, SheetName As String)

Dim sharePoint As Worksheet
Dim Month As Worksheet
Dim spRange As Range
Dim cell As Range

Set sharePoint = Sheets("Sharepoint")
Set Month = Sheets(SheetName)
Set spRange = sharePoint.Range("A2")
Set spRange = sharePoint.Range("A2:" & spRange.End(xlDown).Address)
For Each cell In spRange
If Format(cell.Value, "MM") = MonthNumber Then
copyRowTo sharePoint.Range(cell.Row & ":" & cell.Row), Month
End If
Next cell

End Sub

Sub copyRowTo(rng As Range, ws As Worksheet)
Dim newRange As Range
Set newRange = ws.Range("A1")
If newRange.Offset(1).Value <> "" Then
Set newRange = newRange.End(xlDown).Offset(1)
Else
Set newRange = newRange.Offset(1)
End If
rng.Copy
newRange.PasteSpecial (xlPasteAll)
End Sub

</code>Below is MY interpretation of what I think should reflect my function.

'THIS SUB IS MEANT TO BE GETTING CALLED BY THE PRESS OF A BUTTON (WITHIN ANOTHER SUB)

<code>Private Sub MoveData(MonthNumber As Integer, SheetName As String) 'DOES NOT EVEN RUN WITH THE RANGES CALLED IN THE BRACKETS

Dim BalSheets As Worksheet 'TARGET WORKBOOK
Dim Month As Worksheet
Dim Day As Range 'USED TO DETERMINE THE DAY PART OF THE MONTH
Dim DateInv As Range 'INVOICE DATE ON THIS WORKBOOK'S WORKSHEET
Dim cell As Range

Set BalSheets = Sheets("Balance Sheets")
Set Month = BalSheets(SheetName)
Set DateInv = ThisWorkbook.Sheets("Sheet1").Range("d18") 'FINDS THE MONTH
Set Day = ThisWorkbook.Sheets("Sheet1").Range("d18") 'FINDS THE DAY?
'Set spRange = sharePoint.Range("A2:" & spRange.End(xlDown).Address) 'NOT LOOKING FOR A RANGE OF CELLS SO I LEFT THIS OUT
'For Each cell In spRange

'PRESUMING THIS LOCATES THE "MONTH" DATE WITHIN THIS WORKBOOK'S WORKSHEET(SHEET1) IN THE CELL D18
'NOW I NEED TO LOCATE THE "DAY" DATE FROM THE DATE WITHIN THE SAME CELL SO THAT THE INVOICE VALUE CAN BE COPIED TO IT'S RESPECTIVE DESTINATION CELL
'THE DESTINATION WORKSHEET WILL HAVE B4:P4 AND B22:Q22 AS THE DAYS 1 TO 15 AND 16-30 FOR EASY VIEWING
'ONCE THIS IS ALL FOUND, I WANT TO COPY THE INVOICE VALUE IN CELL H33 TO THE DESTINATION CELL DETERMINED BY THIS SUB.

If Format(cell.Value, "MM") = MonthNumber Then
copyRowTo BalSheets.Range(cell), Month 'TRYING TO COPY JUST THE ONE CELL, NOT A WHOLE RANGE OF CELLS
End If

'Next cell

End Sub

Private Sub copyRowTo(rng As Range, ws As Worksheet) 'NOT TOO SURE ABOUT HOW THIS SUB OPERATES

Dim newRange As Range

Set newRange = ws.Range("A2") 'THIS SHOULD BE THE DESTINATION CELL DETERMINED IN THE PREVIOUS SUB (BETWEEN B4:P4 AND B22"Q22)
'If newRange.Offset(1).Value <> "" Then 'NOT SURE IF THIS IS NEEDED
Set newRange = newRange.Day 'OR WHATEVER IT WOULD BE?
'Else
'Set newRange = newRange.Offset(1)
'End If
rng.Copy
newRange.PasteSpecial (xlPasteAll)
End Sub
</code>Cheers,

Alex
 
Upvote 0
Thanks for getting back to me Trevor.

I have to admit i never even knew the "Immediate window" existed.
It looks like a brilliant tool even though I'm not fully aware of it's full function.

I have tried the formula and noticed how it prints the month and day however am not able to go further with this. I have tried to use the "IF" statements to print a message box IF the month is 'XX' but with no luck.

I have to say that although I have played a fair bit with excel vba, I am still very much a beginner and there is still a lot i don't know about programming.

I have searched very broadly for anything close to what I need to make this work and the closest possible function is listed below. It is from http://stackoverflow.com/questions/...opy-rows-to-another-worksheet/6167187#6167187
However it uses sharepoint, which I have no idea of, but this is the model I tried to modify to do what I need to do, and again with no luck.

Below that I have pasted what I thought would be a working model of what I need, again with no luck.

I'm so far lost for even knowing where to look for information or where to begin learning this that I don't know what to do.

I say again, I really appreciate your help because I feel hopelessly lost with this.


<code>Public Sub MoveData(MonthNumber As Integer, SheetName As String)

Dim sharePoint As Worksheet
Dim Month As Worksheet
Dim spRange As Range
Dim cell As Range

Set sharePoint = Sheets("Sharepoint")
Set Month = Sheets(SheetName)
Set spRange = sharePoint.Range("A2")
Set spRange = sharePoint.Range("A2:" & spRange.End(xlDown).Address)
For Each cell In spRange
If Format(cell.Value, "MM") = MonthNumber Then
copyRowTo sharePoint.Range(cell.Row & ":" & cell.Row), Month
End If
Next cell

End Sub

Sub copyRowTo(rng As Range, ws As Worksheet)
Dim newRange As Range
Set newRange = ws.Range("A1")
If newRange.Offset(1).Value <> "" Then
Set newRange = newRange.End(xlDown).Offset(1)
Else
Set newRange = newRange.Offset(1)
End If
rng.Copy
newRange.PasteSpecial (xlPasteAll)
End Sub
</code>Below is MY interpretation of what I think should reflect my function.

'THIS SUB IS MEANT TO BE GETTING CALLED BY THE PRESS OF A BUTTON (WITHIN ANOTHER SUB)

<code>Private Sub MoveData(MonthNumber As Integer, SheetName As String) 'DOES NOT EVEN RUN WITH THE RANGES CALLED IN THE BRACKETS

Dim BalSheets As Worksheet 'TARGET WORKBOOK
Dim Month As Worksheet
Dim Day As Range 'USED TO DETERMINE THE DAY PART OF THE MONTH
Dim DateInv As Range 'INVOICE DATE ON THIS WORKBOOK'S WORKSHEET
Dim cell As Range

Set BalSheets = Sheets("Balance Sheets")
Set Month = BalSheets(SheetName)
Set DateInv = ThisWorkbook.Sheets("Sheet1").Range("d18") 'FINDS THE MONTH
Set Day = ThisWorkbook.Sheets("Sheet1").Range("d18") 'FINDS THE DAY?
'Set spRange = sharePoint.Range("A2:" & spRange.End(xlDown).Address) 'NOT LOOKING FOR A RANGE OF CELLS SO I LEFT THIS OUT
'For Each cell In spRange

'PRESUMING THIS LOCATES THE "MONTH" DATE WITHIN THIS WORKBOOK'S WORKSHEET(SHEET1) IN THE CELL D18
'NOW I NEED TO LOCATE THE "DAY" DATE FROM THE DATE WITHIN THE SAME CELL SO THAT THE INVOICE VALUE CAN BE COPIED TO IT'S RESPECTIVE DESTINATION CELL
'THE DESTINATION WORKSHEET WILL HAVE B4:P4 AND B22:Q22 AS THE DAYS 1 TO 15 AND 16-30 FOR EASY VIEWING
'ONCE THIS IS ALL FOUND, I WANT TO COPY THE INVOICE VALUE IN CELL H33 TO THE DESTINATION CELL DETERMINED BY THIS SUB.

If Format(cell.Value, "MM") = MonthNumber Then
copyRowTo BalSheets.Range(cell), Month 'TRYING TO COPY JUST THE ONE CELL, NOT A WHOLE RANGE OF CELLS
End If

'Next cell

End Sub

Private Sub copyRowTo(rng As Range, ws As Worksheet) 'NOT TOO SURE ABOUT HOW THIS SUB OPERATES

Dim newRange As Range

Set newRange = ws.Range("A2") 'THIS SHOULD BE THE DESTINATION CELL DETERMINED IN THE PREVIOUS SUB (BETWEEN B4:P4 AND B22"Q22)
'If newRange.Offset(1).Value <> "" Then 'NOT SURE IF THIS IS NEEDED
Set newRange = newRange.Day 'OR WHATEVER IT WOULD BE?
'Else
'Set newRange = newRange.Offset(1)
'End If
rng.Copy
newRange.PasteSpecial (xlPasteAll)
End Sub
</code>Cheers,

Alex
 
Upvote 0
Please disregard this reply, there was an error loading this page and it looked like my question was not posted.
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top