Formatting with macros

amauer

New Member
Joined
May 11, 2012
Messages
33
Hello!

I have a macro that places a formula into a cell. This formula is pulling a value (date and time) from another Excel document. The macro works well, but the format of the cell shows a zero if the reference cell is blank. I am able to change to custom and enter "0:-0;;@" and the zero no longer displays.

Issue: Now my date is displayed as a 5 digit number. How can I adjust the formula in the cell to change the format?

I could create an IF statement on the tab code, but I am unsure what to check for. The cell has the formula.

Any help or possibly just a hint would be great! Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Could you post your macro?
 
Upvote 0
Could you post your macro?

'Dim myMonth As String
'Dim myDate As Range
'Dim myName As String
'
'Set myDate = Sheets("List of Holidays").Range("A16")
'myMonth = Format(myDate, "MMMM")
'
'myName = "='[Monthly File Receives - " & myMonth & ".xlsm]Monthly Files'!$A$3"
'Sheets("Monthly File Retrieval").Range("A3") = myName

So I have the cell function set to pull a value from another document, but the format of the cell needs to be dynamic.
 
Upvote 0
Try:
Code:
Sub amauer()
    Dim myMonth As String
    Dim myDate As Range
    Dim myName As String
    Set myDate = Sheets("List of Holidays").Range("A16")
    myMonth = Format(myDate, "MMMM")
    If Workbooks("Monthly File Receives - " & myMonth & ".xlsm").Sheets("Monthly Files").Range("A3") <> "" Then
        myName = Workbooks("Monthly File Receives - " & myMonth & ".xlsm").Sheets("Monthly Files").Range("A3")
    End If
    Sheets("Monthly File Retrieval").Range("A3") = myName
End Sub
 
Upvote 0
When I run my macro the cell is blank. The macro is inserting the function. The function when looks to another worksheet and transfers the data. Your macro is looking at the current status of the cell, but I need something that will change the format of the cell after the cell pulls in new data from another worksheet. The reference cell will be blank, but will be updated at some point. I can make everything work, but I get "0" in all the cells. I would prefer the cells be blank until the data is available. The only issue is that the cell formatting puts the date/time as a 5 digit number.

I run the macro to add the cell formula. Someone updates the reference cell. My sheet gets updated (cell pulls in the date and time).

My need: The format changes from "Custom" to "Date." Please let me know if you have any questions or if I am not seeing your suggestion correctly.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

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