+ Reply to Thread
Results 1 to 8 of 8

Change code to look in another column

  1. #1
    Registered User
    Join Date
    11-05-2013
    Location
    DK
    MS-Off Ver
    Excel 2013
    Posts
    16

    Change code to look in another column

    Hey guys

    I have "stolen" this peace of code from an old thread in here. I cant figure out how to change the code to go look for a specific word i column "I" insted of column "B".

    Can anyone helt me?

    Manually enter searches on sheet (1).xls

    Please Login or Register  to view this content.
    Last edited by Fotis1991; 11-08-2013 at 06:35 AM. Reason: Pls use code tags around your text as per forum rules.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Change code to look in another column

    Please Login or Register  to view this content.
    the "2"'s are what are defining your column number. Note, your code is a little inefficient, I would suggest rewriting as follows:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-05-2013
    Location
    DK
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Change code to look in another column

    Thanks a lot .

    Your code works . But I'm sorry that I have not made it totally clear what my goal is. Sorry.

    Every day I will get new data into "input". If the new data is labeled "Appels" that entire row has to go to the "Apple" sheet under the already filled rows and be deleted from the "input" sheet. If the new data has no label (blank field), the row should just stay in input sheet.

    Sorry again for the newbie expressions.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Change code to look in another column

    Please Login or Register  to view this content.
    ?

  5. #5
    Registered User
    Join Date
    11-05-2013
    Location
    DK
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Change code to look in another column

    I cant figure out where to place your answer in continuation of previous thread.

    Private Sub CommandButton1_Click()
    Dim search_col, search_term(3), i, l_row
    search_term(1) = "peaches"
    search_term(2) = "pens"
    search_term(3) = "apples"
    search_col = 9
    For i = 1 To Cells(Rows.Count, search_col).End(xlUp).Row
    If Cells(i, search_col) = search_term(1) Then
    With Worksheets("Sheet1")
    l_row = .Cells(Rows.Count, search_col).End(xlUp).Row + 1
    .Range("A" & l_row & ":E" & l_row).Value = Range("A" & i & ":E" & i).Value
    End With
    ElseIf Cells(i, search_col) = search_term(2) Then
    With Worksheets("Sheet2")
    l_row = .Cells(Rows.Count, search_col).End(xlUp).Row + 1
    .Range("A" & l_row & ":E" & l_row).Value = Range("A" & i & ":E" & i).Value
    End With
    ElseIf Cells(i, search_col) = search_term(3) Then
    With Worksheets("Sheet3")
    l_row = .Cells(Rows.Count, search_col).End(xlUp).Row + 1
    .Range("A" & l_row & ":E" & l_row).Value = Range("A" & i & ":E" & i).Value
    End With
    End If

    Dim search_col, i, l_row
    search_col = 9
    For i = Cells(Rows.Count, search_col).End(xlUp).Row To 1 Step -1
    If Not Cells(i, search_col) = "" Then
    With Worksheets(Cells(i, search_col))
    l_row = .Cells(Rows.Count, search_col).End(xlUp).Row + 1
    .Range("A" & l_row & ":E" & l_row).Value = Range("A" & i & ":E" & i).Value
    End With
    Rows(i).Delete
    End If
    Next
    End Sub

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Change code to look in another column

    Ignore the code in post #2, the post in #4 is a separate macro to do what you wanted.

  7. #7
    Registered User
    Join Date
    11-05-2013
    Location
    DK
    MS-Off Ver
    Excel 2013
    Posts
    16

    Re: Change code to look in another column

    I have tried, but I can't get it to work ..

    When there is entered "peaches" in column B in "input", the entire row has to be cut out and inserted into the next empty line in "Sheet1".
    When there is entered "pens" in column B in "input", the entire row has to be cut out and inserted into the next empty line in "Sheet2".
    When there is entered "apples" in column B in "input", the entire row has to be cut out and inserted into the next empty line in "Sheet3".
    When there is nothing entered into column B, the row has to stay in "Input".

    What do I do?

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Change code to look in another column

    You said when it was apples it had to go to the "Apples" sheet!

    Please Login or Register  to view this content.

+ 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. How to change this code into last row isntead of column
    By noelnoy1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2013, 05:15 AM
  2. [SOLVED] Working code for remove #Div,0 in column need a little change
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-18-2013, 05:35 PM
  3. Code change below to find the Customer column by name rather than column letter
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-24-2009, 04:59 PM
  4. code change to refer to column name rather than column position
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2009, 11:04 AM
  5. VB code to total up a column as the value change on another
    By Fernando in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2005, 04:32 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