Results 1 to 1 of 1

for each methods

Threaded View

momo123 for each methods 07-16-2009, 11:37 PM
  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    for each methods

    hello..i have a qns to ask..though it might abit alittle confusing..

    currently i wan to do a for method that runs from row, follow by the country, company and their groups columns..and fill in a value by its row and runs till it completes its range. but i am stuck after searching the values in rows and columns..please ignore the msgboxs as they are just for my reference that the codings are working. =)

    sorry for my codes being so messy. but hope you guys can help me for my report.

    attach is the sample file i have done.


    Sub post()
    
    Fillpost
    
    
    End Sub
    
    
    Public Function Fillpost()
    
        Dim row(1 To 10) As String
        Dim con(1 To 4) As String
        Dim s1, s2 As String
        Dim r(1 To 10) As String
        Const Section1 As String = "Fruits"
        Const Section2 As String = "Cars"
        Const Section3 As String = "Comments"
        
        s1 = InputBox(Prompt:="Please enter Master Template Name", _
              Title:="Master Report Name", Default:="master")
        s2 = InputBox(Prompt:="Please enter Report Template Name", _
              Title:="Report Name", Default:="report")
              
    
    
        row1 = 0
        row2 = 0
        row3 = 0
        row4 = 0
        row5 = 0
        row6 = 0
    
    
    On Error GoTo NotFound
        row1 = Sheets(s1).UsedRange.Find(What:=Section1, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    
        row2 = Sheets(s1).UsedRange.Find(What:=Section2, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    
        row3 = Sheets(s1).UsedRange.Find(What:=Section3, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
     
        row4 = Sheets(s2).UsedRange.Find(What:=Section1, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    
        row5 = Sheets(s2).UsedRange.Find(What:=Section2, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    
        row6 = Sheets(s2).UsedRange.Find(What:=Section3, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    
                    
        row7 = row2 - 1
        row8 = row3 - 1
        row9 = row5 - 1
        row10 = row6 - 1
        con1 = row1 & ":" & row7
        con2 = row2 & ":" & row8
        con3 = row4 & ":" & row9
        con4 = row5 & ":" & row10
    
    
    
            
            
        MsgBox "Fruits in master: " & con1 & vbCrLf & _
        "Cars in master: " & con2
        
        MsgBox "Fruits in report " & con3 & vbCrLf & _
        "Cars in report " & con4
        
            r1 = "Kiwi"
        If Trim(r1) <> "" Then
            With Sheets(s1).Range(con1)
                Set c = .Find(What:=r1, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, MatchCase:=False)
                If Not c Is Nothing Then
                    MsgBox "Kiwi Found"
                Else
                    MsgBox "Kiwi Not found"
                End If
    End With
    End If
            r2 = "Country A"
        If Trim(r2) <> "" Then
            With Sheets(s1).Range("6:40")
                 Set c2 = .Find(What:=r2, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, MatchCase:=False)
                If Not c2 Is Nothing Then
                    MsgBox "Country A Found"
                Else
                    MsgBox "Country A Not found"
                End If
                End With
                End If
                
            r3 = "Company A"
        If Trim(r3) <> "" Then
            With Sheets(s1).Range("6:40")
                 Set c2 = .Find(What:=r3, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, MatchCase:=False)
                If Not c2 Is Nothing Then
                    MsgBox "Company A Found"
                Else
                    MsgBox "Company A not found"
                End If
                End With
                End If
                
             r4 = "With Seed"
        If Trim(r4) <> "" Then
            With Sheets(s1).Range("6:40")
                 Set c2 = .Find(What:=r4, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, MatchCase:=False)
                If Not c2 Is Nothing Then
                    MsgBox "With Seed Found"
                Else
                    MsgBox "With Seed Not found"
                End If
                End With
                End If
    
    
    Exit Function
    NotFound: MsgBox "Item not found"
                
    End Function
    Attached Files Attached Files
    Last edited by momo123; 07-16-2009 at 11:39 PM.

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