Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Asking a user for information and then inserting a row with thatinformation

Hello,

I'm trying to create a VBA Macro where the user presses a button on a
spreadsheet which will start a userform. The userform will ask the
user for specific data regarding a spreadsheet with the following
data:

Row Acct Seq Acct-Descr
1 4111 Stuff
2 4112 Stu
3 4112 1 Stuff
4 4112 2 Stuff2
5 4112 3 Stuff3
6 4113 Stuffs
7 4114 Stuffed

The Row # is the rows normally displayed in Excel on the very left. I
would like to the form to ask what Row # the user would like to insert
ABOVE, what # they want in the acct #, what # they want for a seq #
and what the Account Description should be. The Macro will then read
this information, insert the new row and fill in the specified
cells.

I'm very new to VBA (but have done VB waaaaaaaaaaaay back when). Any
help would be greatly appreciated. I've only successfully gotten it
to insert a row after searching for a value but not for a row #.
Later I'm hoping to get the insertion macro to work on other specified
sheets w/ the same exact layout and # of rows.

Thank you again for any help or advice.

-jas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Asking a user for information and then inserting a row with that i

This should be pretty close what you want; just make whatever customized
changes you want:

Button Code:
Sub Macro1()
frmPartLoc.Show
End Sub

UserForm Code:
Private Sub cmdAdd_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

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

'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("PartsData").Sort.SortFi elds.Clear
ActiveWorkbook.Worksheets("PartsData").Sort.SortFi elds.Add
Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("PartsData").Sort
.SetRange Range("A2:D" & iRow)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select

'clear the data
Me.txtPart.Value = ""
Me.txtLoc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus


End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub

UserForm has 4 TextBoxes: txtPart, txtLoc, txtDate, and txtQty
UserForm also has 2 buttons, named cmdAdd and cmdClose



--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Jason Ubalde" wrote:

Hello,

I'm trying to create a VBA Macro where the user presses a button on a
spreadsheet which will start a userform. The userform will ask the
user for specific data regarding a spreadsheet with the following
data:

Row Acct Seq Acct-Descr
1 4111 Stuff
2 4112 Stu
3 4112 1 Stuff
4 4112 2 Stuff2
5 4112 3 Stuff3
6 4113 Stuffs
7 4114 Stuffed

The Row # is the rows normally displayed in Excel on the very left. I
would like to the form to ask what Row # the user would like to insert
ABOVE, what # they want in the acct #, what # they want for a seq #
and what the Account Description should be. The Macro will then read
this information, insert the new row and fill in the specified
cells.

I'm very new to VBA (but have done VB waaaaaaaaaaaay back when). Any
help would be greatly appreciated. I've only successfully gotten it
to insert a row after searching for a value but not for a row #.
Later I'm hoping to get the insertion macro to work on other specified
sheets w/ the same exact layout and # of rows.

Thank you again for any help or advice.

-jas
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Asking a user for information and then inserting a row with that information

How to create a UserForm.

http://www.contextures.on.ca/xlUserForm01.html

Should be everything you need at Debra's site.


Gord Dibben MS Excel MVP

On Fri, 12 Feb 2010 11:13:49 -0800 (PST), Jason Ubalde
wrote:

Hello,

I'm trying to create a VBA Macro where the user presses a button on a
spreadsheet which will start a userform. The userform will ask the
user for specific data regarding a spreadsheet with the following
data:

Row Acct Seq Acct-Descr
1 4111 Stuff
2 4112 Stu
3 4112 1 Stuff
4 4112 2 Stuff2
5 4112 3 Stuff3
6 4113 Stuffs
7 4114 Stuffed

The Row # is the rows normally displayed in Excel on the very left. I
would like to the form to ask what Row # the user would like to insert
ABOVE, what # they want in the acct #, what # they want for a seq #
and what the Account Description should be. The Macro will then read
this information, insert the new row and fill in the specified
cells.

I'm very new to VBA (but have done VB waaaaaaaaaaaay back when). Any
help would be greatly appreciated. I've only successfully gotten it
to insert a row after searching for a value but not for a row #.
Later I'm hoping to get the insertion macro to work on other specified
sheets w/ the same exact layout and # of rows.

Thank you again for any help or advice.

-jas


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting information from a database with a macro Wombat Excel Discussion (Misc queries) 1 January 11th 10 11:11 AM
Need help with filtering & inserting information :( Desper84AnAnswer Excel Worksheet Functions 5 January 12th 09 03:50 AM
Inserting information from One Sheet to Many Buffulo Alice[_2_] Excel Worksheet Functions 3 December 22nd 08 10:38 PM
Inserting information into a unmade row with a macro Schwimms Excel Discussion (Misc queries) 0 May 23rd 07 09:01 PM
INSERTING INFORMATION IN A CELL WINGCO Excel Discussion (Misc queries) 1 August 8th 06 11:12 PM


All times are GMT +1. The time now is 02:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"