+ Reply to Thread
Results 1 to 8 of 8

Finding a column with a specific title

Hybrid View

  1. #1
    Registered User
    Join Date
    09-03-2010
    Location
    wherever
    MS-Off Ver
    Excel 2003
    Posts
    8

    Finding a column with a specific title

    Hello Everyone,

    My question today is if its possible to have visual basic find the correct heading to a column and make the cell beneath it the active cell.

    Lets say I have columns labeled 1-5 and different serial numbers to put beneath each. On my userform, I would like to make it so when someone enters 1-5 if will put the serial number underneath the correct column. Is it possible to do this?

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a column with a specific title

    Here's something to get you started.
    FindColumn.xls
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Registered User
    Join Date
    09-03-2010
    Location
    wherever
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Finding a column with a specific title

    Thank you for the reply. I edited your code to suit mine but it will not find the column i am looking for. Here is the actual code I have so far

    Private Sub Submit_Click()
        ActiveWorkbook.Sheets("sheet1").Activate
        If (Me.txtRun.Text = "") Then
            MsgBox "Enter the Run Number"
            Exit Sub
        End If
        Dim txtRun As Range
        Set txtRun = ActiveSheet.Range("$B$22:$K$22").Find(Me.txtRun.Text)
        If (txtRun Is Nothing) Then
            MsgBox "Column not found"
            Exit Sub
        End If
        Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(1, 0).Select
        End If
        Loop Until IsEmpty(ActiveCell) = True
        ActiveCell.Value = txtSerial.Value
        ActiveCell.Offset(0, 1) = txtPallet.Value
        If chkProblem = True Then
        Range("N22").Select
        Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(1, 0).Select
        End If
        Loop Until IsEmpty(ActiveCell) = True
        ActiveCell.Value = txtRun.Value
        ActiveCell.Offset(0, 1) = txtSerial.Value
        ActiveCell.Offset(0, 4) = txtPallet.Value
        End If
    End Sub

  4. #4
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a column with a specific title

    You are using ActiveCell when you are not changing cell activity. Try using tryRun.Cells(i,1) where i is the row number you wish to be working with.

  5. #5
    Registered User
    Join Date
    09-03-2010
    Location
    wherever
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Finding a column with a specific title

    Im not exactly sure what you mean. Are you saying when I see
    ActiveCell.Offset(1, 0).Select
    I should use
    txtRun.Cells(1,1).Select
    Im somewhat new to this.

  6. #6
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a column with a specific title

    There were a couple of problems.
    1) you have a variable named txtRun on your input form that conflicts with the range variable name. I used "Col" as the varibale name on the input form.
    2) You needed to select txtRun.Cells(1,1) before starting the loop that searched for the first blank row.
    I commented out all of the code just to show these fixes.
    FindColumn.xls

  7. #7
    Registered User
    Join Date
    09-03-2010
    Location
    wherever
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Finding a column with a specific title

    Ahhhh, It works!!!!!! Thank you very much.

    Just so I understand it better for future references when you wrote
    Dim txtRun As Range
    You were making a new variable name called txtRun correct?

  8. #8
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Finding a column with a specific title

    that is correct. Glad to have you in the forum.

+ Reply to Thread

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