+ Reply to Thread
Results 1 to 3 of 3

Thread: Selecting a number of single cells run time error

  1. #1
    Registered User
    Join Date
    11-16-2008
    Location
    Dubai
    Posts
    73

    Angry Selecting a number of single cells run time error

    Morning All

    I am trying to select specific cells and transfer this data into a new row in a different worksheet.
    The code i am using i used sucessfully on a user form to take the entries from text boxes and place in a row in a new worksheet. I would like to try and do the same thing but on a worksheet rather than a user form.

    My code is

    Private Sub cmdAdd_Click()
    
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Template")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
    
    'check for a policy number
    If Trim(PolNum.Value) = "" Then
      PolNum.SetFocus
      MsgBox "Please enter a policy number"
      Exit Sub
    'copy the data to the database
    
    ws.Cells(iRow, 1).Value = PolNum.Value
    
    'clear the data
    PolNum.Value = ""
    
    End If
    End Sub
    PolNum is a named cell, one of many i hope to just continue the cell names under one another. but i am getting an error. When i used this code in a user form the value for each range was me.name!.value and to clear was Me.Name!.Value = ""

    Am i making a simple mistake or is this not possible to use through a worksheet based form?

    The data entry sheet is called 'Data' and the blank sheet to copy to is 'template'.

    Nick
    Last edited by Nick_in_Dubai; 03-05-2009 at 01:24 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Selecting a number of single cells run time error

    Hello Nick,

    To access a range that is a named range, you must enclose the name in quotes and use it as the index for a Range object, like this...
      ws.Cells(i, Row).Value = Range("PolNum").Value
    
      Range("PolNum").Value = ""
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-16-2008
    Location
    Dubai
    Posts
    73

    Re: Selecting a number of single cells run time error

    Fantastic thank you so much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0