Question : Excel: move 'value "+wildcard" to other column

A column holds different data and a selective  move of values is necessary. In this example  cells which have an 'AT +timestamp' value need moved to next column. What code would be required. I have seached the knowledge base and found many that were close but the hardpart is that after the 'AT'  timestamps are different so a wildcard is needed.

COLUMN A                    after run 'AT *' values to be in COLUMN B

PRIORITY  89
AT  1500
PRIORITY  87
AT  715
PRIORITY  79
PRIORITY  75
PRIORITY  75
EXCEPT  HCZ

Many  thanks.

Answer : Excel: move 'value "+wildcard" to other column

I always think that questions that involve taking the time to write code are worth more than a simple question that just gets an answer based on general knowledge...

I've modified my code so that it'll keep going until you get 15 blank lines in a row.  I'm assuming that this will be enough of a check to assume that the data has ended.

I changed this do you can call the function like this:

DoTheSearch "String to Search For at Beginning of Line", "COL"

where COL is the column letter that you want to copy this value to.

The example copies anything that starts with "AT " to column B and anything that starts with "PRIORITY " to column C.  Adjust as necessary.

 

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
Public Sub doit()

    DoTheSearch "AT ", "B"
    DoTheSearch "PRIORITY ", "C"

End Sub

Private Sub DoTheSearch(sSearchString As String, sMoveToColumn As String)

    Dim i As Long
    Dim iBlankCount As Integer
    
    
    i = 1
     
    
    While iBlankCount < 15
        
        If Len(Range("A" & i)) = 0 Then
            iBlankCount = iBlankCount + 1
        Else
            iBlankCount = 0
        End If
        
        If Left(Range("A" & i), Len(sSearchString)) = sSearchString Then
            Range(sMoveToColumn & i) = Range("A" & i)
        End If
        i = i + 1
    Wend

End Sub
Random Solutions  
 
programming4us programming4us