airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
good day mate,
I decided to try converting my MS Access Form to Excel Userform (have a valid reason), so my would be series of question for the days ahead starts now...
I have a Table with a Header with different capitalization of text entry (ie. Date, DATE, DaTe, date)
what I would like to achieve is search the first row (table header) is such header contains a string of "date" in it, that particular column gets converted to DATE format (dd/mm/yyyy) in the included Sample Table four (4) columns should be converted to DATE format
I search a few dozen excel forum already but came up empty. so far code includes,
CCTO
Sample Table
I decided to try converting my MS Access Form to Excel Userform (have a valid reason), so my would be series of question for the days ahead starts now...
I have a Table with a Header with different capitalization of text entry (ie. Date, DATE, DaTe, date)
what I would like to achieve is search the first row (table header) is such header contains a string of "date" in it, that particular column gets converted to DATE format (dd/mm/yyyy) in the included Sample Table four (4) columns should be converted to DATE format
I search a few dozen excel forum already but came up empty. so far code includes,
CCTO
VBA Code:
Dim rFind As Range
With ThisWorkbook.Sheets("Sheet1").Rows(1)
Set rFind = .Find(What:="*DATE*", Lookat:=xlPart, MatchCase:=False, SearchFormat:=False)
If Not rFind Is Nothing Then
MsgBox "Col: " & rFind.Column & ", Row: " & rFind.Row
End If
End With
'2nd example
For Each Ws In ActiveWorkbook.Worksheets
With Ws
If .Index <> 1 Then
Dim rngSearch As Range, rngLast As Range, rngFound As Range
Dim strFirstAddress As String
Set rngSearch = .Range("A1:CH1")
Set rngLast = rngSearch.Cells(rngSearch.Cells.Count)
Set rngFound = rngSearch.Find("*DATE*", after:=rngLast, LookIn:=xlValues, Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not rngFound Is Nothing Then
strFirstAddress = rngFound.Address
Do
Set rngFound = rngSearch.FindNext(rngFound)
DEBUG.PRINT strFirstAddress
Loop Until rngFound.Address = strFirstAddress
End If
End If
End With
Next Ws
Sample Table
ULTIMATE GENERATOR.xlsm | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | |||
1 | col 1 | col 2 | date enrolled | col 3 | col 6 | Date Exited | col 8 | col 10 | DATE Returned | col 12 | col 13 | DaTe Encoded | col 15 | time Encoded | ||
2 | lorem sum | lorem sum | 2016-01-14 | lorem sum | lorem sum | 2016-01-14 | lorem sum | lorem sum | 2016-04-06 11:56:00 | lorem sum | lorem sum | 2016-01-14 | lorem sum | 10:30:00 | ||
3 | lorem sum | lorem sum | 2015-12-31 | lorem sum | lorem sum | 2016-01-01 | lorem sum | lorem sum | 2016-04-07 02:50:55 | lorem sum | lorem sum | 2015-12-31 | lorem sum | 13:15:00 | ||
4 | lorem sum | lorem sum | 2016-01-03 | lorem sum | lorem sum | 2016-01-03 | lorem sum | lorem sum | 2016-04-07 04:50:40 | lorem sum | lorem sum | 2016-01-03 | lorem sum | 07:50:00 | ||
5 | lorem sum | lorem sum | 2016-01-06 | lorem sum | lorem sum | 2016-01-06 | lorem sum | lorem sum | 2016-04-07 11:15:51 | lorem sum | lorem sum | 2016-01-06 | lorem sum | 11:30:00 | ||
6 | lorem sum | lorem sum | 2016-01-06 | lorem sum | lorem sum | 2016-01-06 | lorem sum | lorem sum | 2016-04-07 11:44:58 | lorem sum | lorem sum | 2016-01-06 | lorem sum | 19:00:00 | ||
7 | lorem sum | lorem sum | 2016-01-08 | lorem sum | lorem sum | 2016-01-08 | lorem sum | lorem sum | 2016-04-07 12:03:21 | lorem sum | lorem sum | 2016-01-08 | lorem sum | 14:20:00 | ||
8 | lorem sum | lorem sum | 2016-01-09 | lorem sum | lorem sum | 2016-01-09 | lorem sum | lorem sum | 2016-04-07 12:31:30 | lorem sum | lorem sum | 2016-01-09 | lorem sum | 19:50:00 | ||
9 | lorem sum | lorem sum | 2016-01-15 | lorem sum | lorem sum | 2016-01-15 | lorem sum | lorem sum | 2016-04-07 13:12:07 | lorem sum | lorem sum | 2016-01-15 | lorem sum | 18:40:00 | ||
10 | lorem sum | lorem sum | 2016-01-16 | lorem sum | lorem sum | 2016-01-16 | lorem sum | lorem sum | 2016-04-07 13:25:24 | lorem sum | lorem sum | 2016-01-16 | lorem sum | 21:55:00 | ||
11 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-04-07 13:39:07 | lorem sum | lorem sum | 2016-01-17 | lorem sum | 23:10:00 | ||
12 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-04-07 13:57:58 | lorem sum | lorem sum | 2016-01-17 | lorem sum | 23:50:00 | ||
13 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-01-17 | lorem sum | lorem sum | 2016-04-07 17:35:44 | lorem sum | lorem sum | 2016-01-17 | lorem sum | 09:45:00 | ||
14 | lorem sum | lorem sum | 2016-01-20 | lorem sum | lorem sum | 2016-01-20 | lorem sum | lorem sum | 2016-04-07 17:52:26 | lorem sum | lorem sum | 2016-01-20 | lorem sum | 23:35:00 | ||
15 | lorem sum | lorem sum | 2016-01-19 | lorem sum | lorem sum | 2016-01-19 | lorem sum | lorem sum | 2016-04-08 00:46:37 | lorem sum | lorem sum | 2016-01-19 | lorem sum | 04:10:00 | ||
16 | lorem sum | lorem sum | 2016-01-30 | lorem sum | lorem sum | 2016-01-30 | lorem sum | lorem sum | 2016-04-08 01:40:00 | lorem sum | lorem sum | 2016-01-30 | lorem sum | 00:30:00 | ||
17 | lorem sum | lorem sum | 2016-01-30 | lorem sum | lorem sum | 2016-01-30 | lorem sum | lorem sum | 2016-04-08 01:57:10 | lorem sum | lorem sum | 2016-01-30 | lorem sum | 14:50:00 | ||
18 | lorem sum | lorem sum | 2016-01-31 | lorem sum | lorem sum | 2016-01-31 | lorem sum | lorem sum | 2016-04-08 02:11:56 | lorem sum | lorem sum | 2016-01-31 | lorem sum | 03:00:00 | ||
19 | lorem sum | lorem sum | 2016-02-01 | lorem sum | lorem sum | 2016-02-03 | lorem sum | lorem sum | 2016-04-08 06:45:30 | lorem sum | lorem sum | 2016-02-01 | lorem sum | 12:45:00 | ||
20 | lorem sum | lorem sum | 2016-02-03 | lorem sum | lorem sum | 2016-02-03 | lorem sum | lorem sum | 2016-04-08 10:11:47 | lorem sum | lorem sum | 2016-02-03 | lorem sum | 22:05:00 | ||
Sheet1 (3) |