+ Reply to Thread
Results 1 to 10 of 10

Thread: Find function problem

  1. #1
    Registered User
    Join Date
    11-24-2010
    Location
    Southampton, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Find function problem

    Below is the section of code that I am having problems with. I've got a table of data which i am trying to manipulate onto another sheet in a presentable form to customers. Depending on the header of the column I would like the corresponding value to go in one of two columns. If the header contains 'freq' in the title, (not all are just freq, there are other headers containing that string as well) then I want it to go one side, if it does not then it needs to go on the other.

    I have an array with the data, am able to get the function to look at the headers, but the .find function does not seem to return 'True' when the string is present, it just returns all searches as false.

    I hope that makes sense, if anyone has any ideas it would be hugely appreciated.

    Apologies for confusing use of variables for colNumber and colLetter, there is a seperate function to take the 'aloop' number and return the corresponding column letter, confusingly I decided to call this final variable colNumber - it is in fact just the letter of the column that I want.

                
                Dim aloop As Integer
                Dim valueloop As Integer
                    valueloop = 6
                Dim freqloop As Integer
                    freqloop = 6
                Dim Found As String
                Dim SearchFor As String
                    SearchFor = Workbooks(myFileName).Worksheets("caretaking").Cells(1, 5).Value
                Dim ColNumber As String
                    
                
                For m = 1 To intLocationCount
                    If labeltemp.Caption = DataCT(m, 1) Then
    
                        For aloop = 4 To 28
                        
                            ColNumber = ColLetter(aloop)
                            Found = vbNothing
                            With Workbooks(myFileName).Worksheets("caretaking").Range(ColNumber & "1")
                                On Error Resume Next
                                Found = .Find(What:=SearchFor, LookIn:=xlValues, After:=.Cells(1, 1), _
                                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
                                On Error GoTo 0
                            End With
                
                            If Found = True Then
                                Cells(freqloop, 4).Value = DataCT(m, aloop - 1)
                                freqloop = freqloop + 1
                            Else
                                Cells(valueloop, 2).Value = DataCT(m, aloop - 1)
                                valueloop = valueloop + 1
                            End If
                                
                        Next aloop
                        
                    End If
                Next m

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find function problems - 2 days on this now, please help!

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    11-24-2010
    Location
    Southampton, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Find function problems - 2 days on this now, please help!

    Main Menu -> Select 'Aldershot' in Location -> Select 'produce costings breakdown'

    New book is created with a template sheet, data should be filtered into B and D columns under relevant areas.

    The code behind the MAIN MENU form has a 2/3 of the way down marking the mostly relevant area.
    Attached Files Attached Files

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find function problems - 2 days on this now, please help!

    I can't see why you are using a loop. I would autofilter the sheet based on the selection then use the filtered range.

    All your lookup formulas have Ref# errors
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Registered User
    Join Date
    11-24-2010
    Location
    Southampton, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Find function problems - 2 days on this now, please help!

    I'm pretty new to all this, loops are something I understand for the most part. What do you mean by auto filter the sheet based on the selection?

    The ref errors are because i ripped out all the other sheets in the book, its fine though, I just need to know how to get the data into the correct columns.

  6. #6
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find function problems - 2 days on this now, please help!

    Will there be only one row for each Location in the caretaking sheet?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  7. #7
    Registered User
    Join Date
    11-24-2010
    Location
    Southampton, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Find function problems - 2 days on this now, please help!

    yes, the entry that is there is the same format for all of them, one line per entry. i just can't figure our why the .find function won't work,

  8. #8
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find function problems - 2 days on this now, please help!

    I wouldn't bother with all that code. Try this, look at the example. This is the code that populates the "invoice"

    Private Sub comboLocationCT_Change()
        Dim Rw As Long
        Dim Rw1 As Long
        Dim y As Long
        Rw = Me.comboLocationCT.ListIndex + 2
        Rw1 = 6
        
        With Sheets("template caretaking")
        For y = 4 To 22 Step 2
        .Cells(Rw1, 2).Value = Sheets("caretaking").Cells(Rw, y).Value
        .Cells(Rw1, 4).Value = Sheets("caretaking").Cells(Rw, y + 1).Value
        Rw1 = Rw1 + 1
        Next y
        End With
    End Sub
    
    
    
    Private Sub UserForm_Initialize()
    'populate the selection box with area choices
      Dim rList As Range
    With Sheet2
      Set rList = .Range(.Cells(2, 1), .Cells(.Rows.count, 1).End(xlUp))
    End With
        Me.comboLocationCT.List = rList.Value
      
    End Sub
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  9. #9
    Registered User
    Join Date
    11-24-2010
    Location
    Southampton, UK
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Find function problems - 2 days on this now, please help!

    I will try and incorporate that into it, looks good though.

    Any ideas why the find function from the original wouldnt work though?

  10. #10
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find function problem

    I didn't have time to work through your code. I'm at work at the moment
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0