+ Reply to Thread
Results 1 to 2 of 2

When cell is blank sendkeys {UP}

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2015
    Location
    wisconsin, united states
    MS-Off Ver
    2010
    Posts
    47

    When cell is blank sendkeys {UP}

    If someone could help me with this I'd greatly appreciate it and be in your debt for eternity...

    I looking to make the code send keys {UP} when a blank cell is found...but holding everything true...

    Option Explicit
    
    Public waitTill As Date
    
    #If VBA7 And Win64 Then
        ' 64 bit Excel
        'The following line is supposed to be RED in 32 bit Excel
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #Else
        ' 32 bit Excel
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If
    
    
    
    Sub Lookup()
      Dim iColumn As Long
       Dim iLastColumn As Long
       Dim iRow As Long
       
       Dim bNeedMore As Boolean
       
       Dim Sel As String
       Dim MoveDown As String
       Dim pH As Single
       Dim Program As String
       Dim sValue As String
    
    
       iLastColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
      For iColumn = 1 To iLastColumn
      
         'Reset the Row to the row before the first row
         iRow = 0
         
         Debug.Print "''''''''''''''''''"
         'Loop Until there is a blank value in a cell
         bNeedMore = True
         While bNeedMore = True
         
           'Increment the Row Number
           'Get the next value as text without leading and trailing spaces
           iRow = iRow + 1
           sValue = Trim(Cells(iRow, iColumn).Value)
           Debug.Print iRow, iColumn, sValue             'Output to Immediate Window (CTRL G) in debugger
    
          If IsNumeric(sValue) Then
    
            'Convert the string to a numeric value
             pH = CSng(sValue)
    
            'Process as required
             If pH >= 1 Then
               Program = pH 'PROGRAM IS NOW THE OUTPUT TO A SECOND APP
             ElseIf pH < 1 Then
               Program = ""
             End If
    
          Else
           
             'Cell value is NOT a number - done processing this column
             bNeedMore = False
             Program = ""
             Debug.Print "''''''''''''''''''"
           
           End If
    
          Application.SendKeys "%{ESC}", True
           
           Sleep 1
    
          Application.SendKeys Program, True  'THIS IS WHERE THE OUTPUT OCCURS
           
           Sleep 1                          'ADD THIS LINE
    
          Application.SendKeys "{UP}", True  'THIS IS WHERE THE OUTPUT OCCURS
           
           Sleep 1                          'ADD THIS LINE
           
           Application.SendKeys "%{ESC}", True
    
         
       Wend
       
       Next iColumn
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: When cell is blank sendkeys {UP}

    Try the following (changes in red):
    Sub Lookup()
      Dim iColumn As Long
       Dim iLastColumn As Long
       Dim iRow As Long
       
       Dim bNeedMore As Boolean
       
       Dim Sel As String
       Dim MoveDown As String
       Dim pH As Single
       Dim Program As String
       Dim sValue As String
    
    
       iLastColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
      For iColumn = 1 To iLastColumn
      
         'Reset the Row to the row before the first row
         iRow = 0
         
         Debug.Print "''''''''''''''''''"
         'Loop Until there is a blank value in a cell
         bNeedMore = True
         While bNeedMore = True
         
           'Increment the Row Number
           'Get the next value as text without leading and trailing spaces
           iRow = iRow + 1
           sValue = Trim(Cells(iRow, iColumn).Value)
           Debug.Print iRow, iColumn, sValue             'Output to Immediate Window (CTRL G) in debugger
    
          If IsNumeric(sValue) Then
    
            'Convert the string to a numeric value
             pH = CSng(sValue)
    
            'Process as required
             If pH >= 1 Then
               Program = pH 'PROGRAM IS NOW THE OUTPUT TO A SECOND APP
             ElseIf pH < 1 Then
               Program = ""
             End If
    
          Else
           
             'Send the Keycode for the UP ARROW KEY
             'only if the value in the cell is BLANK
             '(i.e. 0 length after removing leading and trailing Spaces)
             If Len(sValue) = 0 Then
               Application.SendKeys "{UP}", True
             End If
             
             'Cell value is NOT a number - done processing this column
             bNeedMore = False
             Program = ""
             Debug.Print "''''''''''''''''''"
           
           End If
    
          Application.SendKeys "%{ESC}", True
           
           Sleep 1
    
          Application.SendKeys Program, True  'THIS IS WHERE THE OUTPUT OCCURS
           
           Sleep 1                          'ADD THIS LINE
    
          Application.SendKeys "{UP}", True  'THIS IS WHERE THE OUTPUT OCCURS
           
           Sleep 1                          'ADD THIS LINE
           
           Application.SendKeys "%{ESC}", True
    
         
       Wend
       
       Next iColumn
    
    End Sub

+ 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. Calculate differnce between 2 dates, but if 1 date cell is blank leave cell blank
    By Vicious00013 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-11-2014, 11:31 PM
  2. [SOLVED] Concatenate If Blank - remove blank line if first cell is blank
    By ker9 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-27-2014, 02:14 PM
  3. Replies: 3
    Last Post: 01-23-2014, 12:19 PM
  4. [SOLVED] Cell referenced in formula has no information displayed (shows blank), return blank cell
    By nunayobinezz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-07-2013, 04:51 PM
  5. If cell blank OR another cell blank then show blank, if not display value
    By stevop622 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-09-2013, 04:07 AM

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