TheShyButterfly
New Member
- Joined
- Nov 6, 2011
- Messages
- 43
Hi there, Thank you for your time checking out my query.
I have searched the web and haven't been able to find a solution.
My objective:
When a user enters in data in a particular spreadsheet:
"Daily Log Sheet", Column BA, for example alphanumeric data (CW04VW), I would like it to automatically transform/format it into the CW-04-VW format.
I understand that there are excel function formulas, but this becomes a large file and already has massive amounts of formulas (Vlookups) which is slowing down the workbook considerably, so I wish to have it hard coded via VBA.
I did find some coding which was somewhat useful, however, it only 'formats' selected cells and requires manual initiation to run the code (macro) but I would like it to automatically format the cells in the column as/after the user enters the data.
I adapted the code from Using a Custom Format to Add Dashes
Any assistance would be immensely appreciated.
Kind regards,
TheShyButterfly
I have searched the web and haven't been able to find a solution.
My objective:
When a user enters in data in a particular spreadsheet:
"Daily Log Sheet", Column BA, for example alphanumeric data (CW04VW), I would like it to automatically transform/format it into the CW-04-VW format.
I understand that there are excel function formulas, but this becomes a large file and already has massive amounts of formulas (Vlookups) which is slowing down the workbook considerably, so I wish to have it hard coded via VBA.
I did find some coding which was somewhat useful, however, it only 'formats' selected cells and requires manual initiation to run the code (macro) but I would like it to automatically format the cells in the column as/after the user enters the data.
VBA Code:
Sub DashesIn()
DoDashes ("In")
End Sub
Private Sub DoDashes(What As String)
' from website: https://excelribbon.tips.net/T009394_Using_a_Custom_Format_to_Add_Dashes.html
' Puts dashes after every 2nd character to a total of 6 characters long
'OUTPUT IS IN THIS FORMAT: **-**-**
Dim c As Range
Dim J As Integer
For Each c In Selection.Cells
If c.Value <> "" Then
J = InStr(c.Value, "-")
Select Case What
Case "Out"
While J > 0
c.Value = Left(c.Value, J - 1) & _
Mid(c.Value, J + 1, Len(c.Value))
J = InStr(c.Value, "-")
Wend
Case "In"
If J = 0 Then
c.Value = _
Left(c.Value, 2) & "-" & _
Mid(c.Value, 3, 2) & "-" & _
Right(c.Value, 2)
End If
End Select
End If
Next c
End Sub
I adapted the code from Using a Custom Format to Add Dashes
Any assistance would be immensely appreciated.
Kind regards,
TheShyButterfly