convert formula to code "merge text with date" in merged cells

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello

i have this formula
VBA Code:
=F5&""&TEXT(F4;"yyyy/mm/dd")
the result shows in merged cell from a3:e3 i would this formula convert to code in event worksheet change

i want that because i have to hide column f where f5= text and f4=date i don't want see this formula i can hide this column but i don't find this way is practical i would this by code i try it but i failed to do that (note: if is possible to do that int merged cells from a3:e3 )

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Range("c3").Value = Text("inventory", yyyy / mm / dd)

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Using the upper left cell address for the Merged Cells, does this event code do what you want...
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) Like "F[45]" Then [A3] = [F5&""&TEXT(F4," yyyy/mm/dd")]
End Sub
 
Upvote 0
hi rick

i would directly write text without specific cell like f4,f5 i would only show this from a3:e3 "inventory date 28/06/2020" i don't want the text depend on f4 is it possible do this
VBA Code:
  If Target.Address(0, 0) Like "F[45]" Then [A3] = TEXT("inventory"," yyyy/mm/dd")
actually i no know what means this "F[45]"
 
Upvote 0
You say you don't want the code dependent on cell F4, but your original post said cell F4 contained the date. Are you saying the date is fixed and not variable? Also cell F5 (from your original post) contained a text value... is "Inventory Date" that text? Please clarify what is in which cells and what cell reference the code should be using.
 
Upvote 0
yes i just show the date in cell f4 to reach my idea so the date is depend on today about the text it is always fixed calls inventory
so the topic for instance today should be " inventory date 28/06/2020 and if tomorrow is "inventory date 29/06/2020 and so on as you see i would this topic without linked cells f4,f5 and the date based on today in short words no cells directly write the date based on today and the text is fixed
i hope this help
 
Upvote 0
Okay, given what you just wrote, you would not be using the Change event because nothing is changing... so a simple macro seems what you need (I am guessing you are still writing to cell A3 (which is part of a merged cell consisting of A3:E3) thus overwriting whatever was there previously..
VBA Code:
Sub SetInventoryDate()
  [A3] = ["Inventory "&TEXT(TODAY(),"dd/mm/yyyy")]
End Sub
 
Upvote 0
thanks rick your code works so good about change event i put this code in this event workbook open it changes automatically when i open the file and change the date based on today thanks again
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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