+ Reply to Thread
Results 1 to 5 of 5

Search for multiple string values in the first row of a table and format column values.

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    2

    Search for multiple string values in the first row of a table and format column values.

    Hello all, I'm having a problem searching for multiple string values in the top row of a table and return the column number.

    I want to search for all the table column headers one by one and numberformat the corresponding column values.
    I managed to search for the first string value and to set the numberformat of the column values but now i want to do the same for the next 59 colums.
    Ofcourse, I could repeat this code 59 times, but I guess there is a better way to do it. (e.g. using a loop)

    I would realy appreciate if someone could help.

    [code]
    Dim cellToSearch As Range
    Dim Found As Range
    Dim foundColumn As Long
    Dim searchValue As String
    Dim nSmp As Long

    nSmp = 60 'Number of sample columns

    With Worksheets("Sheet2")

    Set cellToSearch = Sheets("Sheet2").Range(.Cells(1, 1), .Cells(1, nSmp))

    searchValue = "Actual AdBlue dosing rate[g/h]"
    Set Found = cellToSearch.Find(what:=searchValue)

    If Found Is Nothing Then

    Else
    foundColumn = cellToSearch.Find(what:=searchValue).Column

    Sheets("Sheet2").Cells(1, foundColumn).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.NumberFormat = "0.00"
    End If

    End With

    Application.ScreenUpdating = True

    End Sub
    'List of string values to search for
    'Actual AdBlue dosing rate[g/h]
    'Actual AdBlue dosing rate[oz/h]
    'Actual fuel quantity[g/stroke]
    'Actual HC dosing rate[g/h]
    'Actual HC dosing rate[oz/h]
    'AdBlue dosing valve position[-]
    'AdBlue tank heater valve position[-]
    'AdBlue tank level[%]
    'AdBlue tank temperature[C]
    'AdBlue tank temperature[F]
    [\code]

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Search for multiple string values in the first row of a table and format column values

    Hi

    you should use the cells function.

    Please Login or Register  to view this content.
    You can put your "headers" and "formats" into arrays or into a collection so that you can read then off using the same counter

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for multiple string values in the first row of a table and format column values

    "List of string values to search for"
    I put the searched items on a separate sheet(sheet1) in column A. It also makes your task easy as you can easily amend the lists in sheet1.
    Attached Files Attached Files
    Last edited by AB33; 04-12-2013 at 03:03 AM.

  4. #4
    Registered User
    Join Date
    04-11-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Search for multiple string values in the first row of a table and format column values

    AB33, thank you very much. It works like a charm!

    I'm getting more experienced in VBA macro's but looking at your solution I still have a long way to go.

    Thanks!!!

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for multiple string values in the first row of a table and format column values

    Excel,
    You are welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1