Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod crash desktop driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network printer problem ram random registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Add data from a UserFrom to the first empty row in a specific range

Reply  
Thread Tools
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
21-Jul-2010, 01:30 PM #1
Solved: Add data from a UserFrom to the first empty row in a specific range
I have a user form with two combo boxes, an add button and a close button. I would like the users choices from the combo boxes to be added to the worksheet "ReqM" starting with the first blank row on or after row 85, the 2nd choice on row 86 and so on until the users clicks the close button. The following code currently adds the data to the last blank row in the worksheet.

I appreciate any help:

Private Sub cmdAdd_Click()
Dim lRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("Req M")

'Need help with this section:

'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
lPart = Me.cboEmployee.ListIndex

'copy the data to the database
With ws
.Cells(lRow, 1).Value = Me.cboEmployee.Value

.Cells(lRow, 3).Value = Me.cboPosition.Value
End With

'clear the data
Me.cboEmployee.Value = ""
Me.cboPosition.Value = ""
Me.cboEmployee.SetFocus

End Sub
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
21-Jul-2010, 03:26 PM #2
what are you saying? That initially when it first runs, row 85 is empty and that the first empty row ( or cell) is further up? Looking at the code I would say you want Row 85 to get filled in first, and then after that it would automatically fill in.

So I would wrap an IF around that portion to get it started.


I'll just use Column 1 as a reference...


Code:
if Cells(85,1)= "" then

lRow = 85

else

''find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row


end if
__________________
Ziggy

ô¿ô
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
21-Jul-2010, 04:17 PM #3
Not Exactly...I know the code is incorrect as written. Currently it returns the data to the first empty row in the spreadsheet (which is somewhere around row 145).

The user will choose an employee from the first combo box and their position/title from the second combo box. They then will click the add button. I would like the result to be displayed on row 85. They then have the option of choosing additional employees/positions or closing the form. I would like their second choice to appear on line 86, the 3rd choice to appear on line 87 and so on.
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
21-Jul-2010, 05:00 PM #4
Use this example,

I have to run so I could not fully adapt to your example as I was focused on getting the loop working in sync.



Code:
Public Sub test()

Static Y As Double
Dim X As Double

X = 85

    '
    If Cells(X, 1) = "" Then
        
        Y = 85
    
    End If


        Do Until Cells(X, 1) = ""
        X = X + 1
        Loop



    If Y = 0 Then
    
    
    ' Put your Add items here
        Cells(X, 1) = "TEST"
        Y = X + 1
    
    Else
            ' repeat here because the first one is only on the first pass (could call a sub)
        ' Put your Add items here
        Cells(X, 1) = "TEST"
        Y = Y + 1
    
    End If



End Sub
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
23-Jul-2010, 10:24 AM #5
I can't get this quite right...the first choice is being returned to line 87 and any subsequent choice is as well, overriding the first...
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
23-Jul-2010, 10:28 AM #6
if you take exactly what I have, and just run it, it starts on line 85 and carries on?

post your adapted code and I will look.
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
23-Jul-2010, 03:10 PM #7
I didn't save when i tried it earlier. My original code is above. Can you suggest where to insert?
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
24-Jul-2010, 11:22 PM #8
ok here ya go, I put it together for you.
Attached Files
File Type: xls ComboAdd.xls (57.5 KB, 29 views)
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
27-Jul-2010, 12:23 PM #9
Thanks for trying
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
27-Jul-2010, 12:31 PM #10
so that's a... No it doesn't work? You would get better result if you posted a sample what your data looks like ( no personal info).

I think my example does exactly what you asked?
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
28-Jul-2010, 04:30 PM #11
Your example works perfectly. When i entered into my workbook i received an error message. I think it may be because i want the data to be entered on a different worksheet??? I'm just not familiar enough to work it out. On to a different project for a week or so then i may be able to pick it up again. Thanks for taking the time to get me this far
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
28-Jul-2010, 04:36 PM #12
Quote:
Originally Posted by Guest2 View Post
Your example works perfectly. When i entered into my workbook i received an error message. I think it may be because i want the data to be entered on a different worksheet??? I'm just not familiar enough to work it out. On to a different project for a week or so then i may be able to pick it up again. Thanks for taking the time to get me this far
actually I should have thought of that... when you get back to it upload a sample and I can tailor to your book.
Guest2's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Feb 2010
Experience: Beginner
06-Aug-2010, 10:12 AM #13
One sleepless night it came to me...just move the user form to the same worksheet and Voilà, success!
Thanks again
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
06-Aug-2010, 10:14 AM #14
np...cool.... now go get some sleep
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Restore Data from WD Sync External HD kawill Hardware 1 22-Mar-2010 05:00 PM
Copying Data from 1 sheet to the next upon fulfilling certain conditions tokyo3968 Business Applications 0 05-Feb-2010 02:19 AM
Simple Excel Macro to Copy Row from one Sheet to Another exterminar Business Applications 1 14-Aug-2009 06:27 AM
New to the site. KingTech Web & Email 1 03-Jan-2009 03:46 AM
Transferring Data from Old HDD to New PC Slyder6 Hardware 3 22-Aug-2008 09:16 AM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:20 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.