Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Formatting output of Search Entire Workbook and display a column with 16-digit numbers

0

Dears, i used search entire workbook return all results in Excel but i need to change cells format like (date , time, text , border ... Etc) every time doing it reset once press search or clear button, and fix 16 digit format

Answer
Discuss

Discussion

Thanks for your kindly support, please just need to edit 1 point, i have on column 6 data from 16 digits , & tried to format as text with no result its converted to (5.12354E+15) & as special but its converted last digit from right to be zero (5118649865412354) number (4) converted to be (0)
Khaled1980 (rep: 4) May 24, '22 at 7:18 pm
Khaled

That's a separate question really (and I think I answered your original question and the information/ file you supplied).

In the Forum we need you to to give an accurate question and (preferably) also upload upload a representative Excel file (without any personal data) to show your existing macro and data.- that prevents follow-on questions.

You're new to the Forum so I'll see if I can find time later to solve this additional complication (arising since Excel normally works to 15 digit accuracy) within my solution.

Note that this discussion should really be attached to my Answer.
John_Ru (rep: 6142) May 25, '22 at 4:09 am
Thanks for selecting my Answer, Khaled. Will try to fix your secondary problem later today. 
John_Ru (rep: 6142) May 25, '22 at 6:02 am
Khaled. Hope I fixed that for your- see REVISION section in Answer and second file.
John_Ru (rep: 6142) May 25, '22 at 5:28 pm
Thank you very much for your great support.
Khaled1980 (rep: 4) May 25, '22 at 6:59 pm
Add to Discussion

Answers

0
Selected Answer

Hi Khaled and welcome to the Forum.

One simple way to do that is to use the header row as a reference range and apply any formatting you like there - borders, fill, date, time, italics etc. (per column, even though the header text might not be affected by the formatting).

In the attached file I've just put different colour fills in B8:N8 and set the format of D8:N8 as Number but to one decimal place (for the purposes of illustration only).

Then I've added a bit to the end of the code (extract below):

'Go to the next worksheet.
Next ws

'Application.ScreenUpdating = True 'Turn it back on at the end of the macro!

End Sub

as follows (with changes and comments in bold for your guidance):

 
'Go to the next worksheet.
Next ws

' format the results, based on reference row 10
With dashboard.Range("B10:N10")
    ' copy formatting from reference row...
    .Copy
    'paste to all new data
    With .CurrentRegion
        .PasteSpecial xlPasteFormats
        ' but remove Bold apart from first row
        .Offset(1, 0).Font.Bold = False
    End With
End With
End Sub

Now when you click Search, you'll get the data in a coloured table, with borders and number formatting. Just the top row will be bold. The Clear button will work as before (leaving that reference row/formatting in place).

I added Freeze Panes to the sheet at the last minute (so you can scroll down the Search results but still see the bold headings (reference row)

Hope this helps. If so, please don't forget to mark the Answer as Selected (for the guidance of others and to add to each of our reputations on this Forum).

REVISION:

Regarding your secondary issue of displaying more than 16 digits in column 6 (F) of the data, here's a way around that. If you store your account numbers like:  

'5118649865412354

you will see the full number (see cell F2 in worksheet Jan). The problem is that Excel stores them in the arrays as the full string 5118649865412354 (without the leading ') but then reverts to 15-digit accuracy when putting values in cells (so the last 4 becomes a 0).

In the SECOND file below, cell G10 (in the "reference row") is formatted as TEXT.

The code is changed to add a new variable (in bold below):

Sub Data_Search()
' TeachExcel.com

Dim ws As Worksheet
Dim dashboard As Worksheet
Dim dataArray As Variant
Dim datatoShowArray As Variant
Dim MoreThan15Dig As Integer ' identify the column with more than 15 digits e.g. an account number

and I've modified the portion which stored values in the array. If it's in 6 and a string in the array, it adds a single quotation mark so the value is stored as '5118649865412354 and will appear as 5118649865412354 is the Dashboard search results. Additional code is in bold below:

                'MATCH FOUND! Now do something!

                'Loop through the columns in the data range so can get their values.
                For k = 1 To UBound(dataArray, 2)
                    'if it's in the named MoreThan15Dig column and is a string...
                    If k = MoreThan15Dig And VarType(dataArray(i, k)) = vbString Then
                        '...add a single quotation mark to start of string...
                        datatoShowArray(j, k) = Chr(39) & dataArray(i, k)
                        'Add values to the array that will be used to put data into the Dashboard.
                        Else
                        datatoShowArray(j, k) = dataArray(i, k)
                    End If
                Next k

Search for Jim and Name and it will be in the first result row.

Hope this fixes your second problem too.

Discuss

Discussion

If this works for you Khaled, do me a favour please ... kindly edit the title of your question to "Formatting output of Search Entire Workbook and display a column with 16-digit numbers" - this will be better for other users.
John_Ru (rep: 6142) May 25, '22 at 5:34 pm
Thanks for changing the question title as I suggested, Khaled. I chnaged my Answer just but only to put a line of comments in bold.
John_Ru (rep: 6142) May 26, '22 at 12:39 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login