+ Reply to Thread
Results 1 to 9 of 9

Creating IF statement for iRow Entry

Hybrid View

  1. #1
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Creating IF statement for iRow Entry

    What errors are you getting? What is it doing or not doing?

    The only issue I got was that it was putting the row number in column A, but the values in the next row down.

    This worked fine for me:
    Set we = Worksheets("Chart View"): we.Activate
    
    Range("A1").Value = 1
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1) = Range("A" & Range("A" & Rows.Count).End(xlUp).Row) + 1
    
    iRow = Worksheets("Chart View").Range("A65536").End(xlUp).Row 'Had to delete the "+1" part to get the data to appear on the right row.
    we.Cells(iRow, 2).Value = Me.ComboBox2.Value
    If Me.ComboBox3.Value = "Apples" Then
    we.Cells(iRow, 3).Value = TextBox1.Value
    End If
    If Me.ComboBox3.Value = "Oranges" Then
    we.Cells(iRow, 4).Value = TextBox1.Value
    End If

  2. #2
    Forum Contributor
    Join Date
    06-06-2012
    Location
    Toronto, ON
    MS-Off Ver
    Office 365
    Posts
    138

    Re: Creating IF statement for iRow Entry

    So the user is using a userform I built to input the data onto the sheet.

    Its working as its supposed to except the value in textbox 1 needs to be put in one cell or the other depending on the selection of apples or oranges from the combo-box. Here is the full code, when the userform is submitted the data from the userform is actually getting entered on two sheets. The error Im getting is:
    "Runtime Error, Script out of Range", and its highlighting the line:

    "set ws worksheets("records"): ws.Activate"

    Private Sub CommandButton1_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Dim we As Worksheet
    Dim Count, temp As Integer
    
    
    For Count = 1 To 3
    
    
    Next
    
    Set ws = Worksheets("Records"): ws.Activate
    '''find  first empty row in database
    ''iRow = ws.Cells(Rows.Count, 1) .End(xlUp).Offset(1, 0).Row
    'revised code to avoid problems with Excel tables in newer versions
    iRow = Worksheets("Records").Range("A65536").End(xlUp).Row + 1
    
    ws.Cells(iRow, 1).Value = Me.ComboBox1.Value
    ws.Cells(iRow, 2).Value = Me.ComboBox2.Value
    ws.Cells(iRow, 3).Value = Me.ComboBox3.Value
    ws.Cells(iRow, 4).Value = Me.TextBox1.Value
    ws.Cells(iRow, 5).Value = Me.DTPicker1.Value
    ws.Cells(iRow, 6).Value = Me.DTPicker2.Value
    
    Set we = Worksheets("Chart View"): we.Activate
    Range("A1").Value = 1
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1) = Range("A" & Range("A" & Rows.Count).End(xlUp).Row) + 1
    
    
    iRow = Worksheets("Chart View").Range("A65536").End(xlUp).Row 'Had to delete the "+1" part to get the data to appear on the right row.
    we.Cells(iRow, 2).Value = Me.ComboBox2.Value
    If Me.ComboBox3.Value = "Apples" Then
    we.Cells(iRow, 3).Value = TextBox1.Value
    End If
    If Me.ComboBox3.Value = "Oranges" Then
    we.Cells(iRow, 4).Value = TextBox1.Value
    End If
    we.Cells(iRow, 5).Value = Me.DTPicker1.Value
    we.Cells(iRow, 6).Value = Me.DTPicker2.Value
    
        
    
    End Sub
    Quote Originally Posted by Whizbang View Post
    What errors are you getting? What is it doing or not doing?

    The only issue I got was that it was putting the row number in column A, but the values in the next row down.

    This worked fine for me:
    Set we = Worksheets("Chart View"): we.Activate
    
    Range("A1").Value = 1
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1) = Range("A" & Range("A" & Rows.Count).End(xlUp).Row) + 1
    
    iRow = Worksheets("Chart View").Range("A65536").End(xlUp).Row 'Had to delete the "+1" part to get the data to appear on the right row.
    we.Cells(iRow, 2).Value = Me.ComboBox2.Value
    If Me.ComboBox3.Value = "Apples" Then
    we.Cells(iRow, 3).Value = TextBox1.Value
    End If
    If Me.ComboBox3.Value = "Oranges" Then
    we.Cells(iRow, 4).Value = TextBox1.Value
    End If
    Last edited by excelenergy; 09-29-2014 at 04:22 PM.

  3. #3
    Forum Contributor
    Join Date
    06-06-2012
    Location
    Toronto, ON
    MS-Off Ver
    Office 365
    Posts
    138

    Re: Creating IF statement for iRow Entry

    Basically, if 'Apples' is selected then the value of textbox1 should go into cell B3, if oranges is selected the value of textbox1 would go into cell B4

+ 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. Combinations and iRow formula
    By Fitz1567 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2013, 12:13 AM
  2. [SOLVED] Creating a Record Entry Bar - Possible?
    By diggers16 in forum Excel General
    Replies: 15
    Last Post: 12-27-2012, 03:04 PM
  3. [SOLVED] Issue using iRow
    By faoltaem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2012, 03:00 AM
  4. Define "iRow" as Row displayed after data is filtered
    By mgdmeyers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2012, 10:41 AM
  5. Arranging data:Dim iRow As Long
    By vijaya in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2005, 12:45 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