Automatically fill and size cell/column

jsavoor

New Member
Joined
Dec 14, 2008
Messages
23
Hi

I have seen several snippets to change a series of columns to autofit using the Worksheet_Change method.

What I am looking to do is the following:
  1. I have a spreadsheet that records changes
  2. Columns J:Z are used to record the changes.
  3. When the user enters a value in any cell within that column range the following should happen...
    1. the column width should change to 40
    2. the font of the text in that cell should change to 9pt
    3. the current date and time + a colon + space should be added to the beginning of the text in the cell as soon as the cursor moves out.
    4. So it should look like... 10/04/2013 11:00AM: blah blah blah

Could someone please assist in a macro that does this?

Thanks in advance for any help.

Jay
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this code in the sheet's module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Columns("J:Z"), Target) Is Nothing And Target.Cells.Count = 1 Then
        Columns(Target.Column).ColumnWidth = 40
        Target.Font.Size = 9
        Application.EnableEvents = False
        Target.Value = Format(Now, "dd/mm/yyyy Hh:NnAM/PM") & ": " & Target.Value
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
John, I am so grateful to. Works beautifully.

Have a great weekend.

warm regds. Jay

Try this code in the sheet's module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Columns("J:Z"), Target) Is Nothing And Target.Cells.Count = 1 Then
        Columns(Target.Column).ColumnWidth = 40
        Target.Font.Size = 9
        Application.EnableEvents = False
        Target.Value = Format(Now, "dd/mm/yyyy Hh:NnAM/PM") & ": " & Target.Value
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
In case it is possible that more than one cell is changed at a time (eg Entry with Ctrl+Enter or Copy/Paste from another range) here is a variation that will cope with than scenario too.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Columns("J:Z"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      With c
        .EntireColumn.ColumnWidth = 40
        .Font.Size = 9
        .Value = Format(Now, "dd/mm/yyyy hh:mmAM/PM: ") & .Value
      End With
    Next c
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,196,102
Messages
6,013,464
Members
441,767
Latest member
Craigh4444

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