+ Reply to Thread
Results 1 to 2 of 2

If Range("K" & ActiveCell.Row) = "" Then (ERROR)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    If Range("K" & ActiveCell.Row) = "" Then (ERROR)

    Good day,
    Just trying to find out what I am missing as this code of mine doesn't seem to see what is there and not:

    Code

    
    Dim rngReqNo As Range
    Dim rngConNo As Range
    Dim strReqNo As String
    Dim strRetenderLetter As String
    Dim rngFoundReqNo As Range
    
    
    
    Private Sub CommandButton1_Click()
        Application.ScreenUpdating = False
        Application.EnableEvents = False
       
     
          
        Set rngReqNo = ActiveCell
        Set rngConNo = ActiveCell.Offset(0, 2)
        strReqNo = rngConNo.Value
        
    
    
        Set rngFoundReqNo = Sheets("Report").Range("N:N").Find(What:=strReqNo & "*", _
        LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
        MatchCase:=False)
       
    
     
        If Not rngFoundReqNo Is Nothing Then
            rngFoundReqNo.Offset(, 1).Value = rngReqNo.Offset(, 3).Value 'D to O
            rngFoundReqNo.Offset(, 2).Value = rngReqNo.Offset(, 7).Value 'H to P
            rngFoundReqNo.Offset(, 3).Value = rngReqNo.Offset(, 8).Value 'I to Q
            rngFoundReqNo.Offset(, 8).Value = rngReqNo.Offset(, 9).Value 'J to V
            rngFoundReqNo.Offset(, 9).Value = rngReqNo.Offset(, 11).Value 'J to V
            rngFoundReqNo.Offset(, 11).Value = "hs631" 'adds to Y
            rngFoundReqNo.Offset(, 12).Value = "=SUM(RC[-22]-RC[-23])" 'adds to Z
            rngFoundReqNo.Offset(, 13).Value = "=SUM(RC[-18]-RC[-23])" 'adds to AA
            rngFoundReqNo.Offset(, 14).Value = "=SUM(RC[-18]-RC[-19])" 'adds to AB
            rngFoundReqNo.Offset(, 15).Value = "=SUM(RC[-12]-RC[-26])" 'adds to AC
     
    
       
            If Range("K" & ActiveCell.Row) = "" Then
    ''       rngFoundReqNo.Offset(, 7).Value = rngReqNo.Offset(, 10).Value 'K to U
            With rngFoundReqNo.EntireRow 'insert a new row underneath
              .Range("A1:AC1").Interior.ColorIndex = 15
              .Range("S1").Value = "Administration"
              .Offset(1).Insert
              .Offset(1).Range("A1:AC1").Value = .Range("A1:AC1").Value
              .Offset(1).Range("S1").Value = "Firm"
              .Offset(1).Range("A1:AC1").Interior.ColorIndex = 36
            End With
            End If
    
    
        
        'This clears the content in the selected row from A to L and Sort row 5 to 30
        Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 12)).ClearContents
      
    
         
        With ActiveWorkbook.Worksheets("Contracts").Sort
            .SetRange Range("A5:L20")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
     
    
       
        With ActiveWorkbook.Worksheets("Report").Sort
            .SetRange Range("A5:AC100")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        End If
      
    
      
        Unload Me
        Sheets("Report").Select
        Range("A5").Select
        Sheets("Contracts").Select
        Range("A5").Select
            
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    This codes (On my Command Button Click) will search for the matching text in my Column N and add the rest of the information on my Active row...I added a If there is something in my Active Row "K" then add the following procedure. But no matter what I do it will still run the procedure...

    What am I doing wrong? Is it not at the right place?
    Last edited by Excelnoub; 12-08-2013 at 04:14 PM. Reason: Repost Sheet Code

  2. #2
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: If Range("K" & ActiveCell.Row) = "" Then (ERROR)

    Sorry Guys Found it here is the full code:

    
    Dim rngReqNo As Range
    Dim rngConNo As Range
    Dim strReqNo As String
    Dim strRetenderLetter As String
    Dim rngFoundReqNo As Range
      
          
        Set rngReqNo = ActiveCell
        Set rngConNo = ActiveCell.Offset(0, 2)
        strReqNo = rngConNo.Value
        
    
        Set rngFoundReqNo = Sheets("Report").Range("N:N").Find(What:=strReqNo & "*", _
        LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
        MatchCase:=False)
        
    
        If Not rngFoundReqNo Is Nothing Then
            rngFoundReqNo.Offset(, 1).Value = rngReqNo.Offset(, 3).Value 'D to O
            rngFoundReqNo.Offset(, 2).Value = rngReqNo.Offset(, 7).Value 'H to P
            rngFoundReqNo.Offset(, 3).Value = rngReqNo.Offset(, 8).Value 'I to Q
            rngFoundReqNo.Offset(, 8).Value = rngReqNo.Offset(, 9).Value 'J to V
            rngFoundReqNo.Offset(, 9).Value = rngReqNo.Offset(, 11).Value 'J to V
            rngFoundReqNo.Offset(, 11).Value = "hs631" 'adds to Y
            rngFoundReqNo.Offset(, 12).Value = "=SUM(RC[-22]-RC[-23])" 'adds to Z
            rngFoundReqNo.Offset(, 13).Value = "=SUM(RC[-18]-RC[-23])" 'adds to AA
            rngFoundReqNo.Offset(, 14).Value = "=SUM(RC[-18]-RC[-19])" 'adds to AB
            rngFoundReqNo.Offset(, 15).Value = "=SUM(RC[-12]-RC[-26])" 'adds to AC
            
        'This clears the content in the selected row from A to L and Sort row 5 to 30
       
     
    
      
      If rngReqNo.Offset(, 10).Value <> "" Then ' was triggering the wrong column
      rngFoundReqNo.Offset(, 7).Value = rngReqNo.Offset(, 10).Value 'K to U
         With rngFoundReqNo.EntireRow 'insert a new row underneath
              .Range("A1:AC1").Interior.ColorIndex = 15
              .Range("S1").Value = "Administration"
              .Offset(1).Insert
              .Offset(1).Range("A1:AC1").Value = .Range("A1:AC1").Value
              .Offset(1).Range("A1:AC1").Interior.ColorIndex = 36
              .Offset(1).Range("S1").Value = "Firm"
         End With
      End If
    
     
    
       
       Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 12)).ClearContents
     
    
          
           
        With ActiveWorkbook.Worksheets("Contracts").Sort
            .SetRange Range("A5:L20")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
       
    
     
        With ActiveWorkbook.Worksheets("Report").Sort
            .SetRange Range("A5:AC100")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        
    
    
        End If
    
        
        
        Unload Me
        Sheets("Report").Select
        Range("A5").Select
        Sheets("Contracts").Select
        Range("A5").Select
            
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    End Sub
    Last edited by Excelnoub; 12-08-2013 at 06:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  2. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  3. Macro Error with code "Range("A65536").End(xlUp).EntireRow.Insert"
    By lukasj13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-30-2010, 08:48 PM
  4. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  5. Problem using "Cells" in "Range" "400" error
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2009, 05:46 PM

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