HELP WITH A COUPLE OF SIMPLE FORMULAS FOR A NEW USER

R

rlashmore999

A couple of simple questions. I'd appreciate some help.

1)How do I get a UserForm to open automatically when I open a
worksheet in Excel.

2)MORE IMPORTANTLY....

Can someone supply me with a VBA formula to locate the next empty cell
(or row or column) after entering data in one row to go to the next
for input. The code in the books I am referring to just plain doesn't
work.

3) ALSO MORE IMPORTANTLY
How do I get a command button on a
UserForm
on sheet1 to automatically open a UserForm
on sheet2 to
enter new data.
 
N

Norman Jones

Hi R,
1)How do I get a UserForm to open automatically when I open a
worksheet in Excel.

Try:

'=============>>
Private Sub Workbook_Open()
Userform1.Show
End Sub
'<<=============

This is workbook event code and should be pasted into
the workbook's ThisWorkbook module *not* a standard
module or a sheet module:

Right-click the Excel icon on the worksheet (or the icon
to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
Can someone supply me with a VBA formula to locate the next empty cell
(or row or column) after entering data in one row to go to the next
for input. The code in the books I am referring to just plain doesn't
work.

It is invariably useful to post the problematic code.

However to return the next empty cell in column A and to
return the first empty column in row 1, try:

'================>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim iRow As Long
Dim iCol As Long

Set WB = Workbooks("MyBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

With SH
iRow = .Cells(.Rows.Count, "A").End(xlUp). _
Offset(1, 0).Row
iCol = .Cells(1, .Columns.Count).End(xlToLeft). _
Offset(0, 1).Column
End With

MsgBox Prompt:="Next row = " & iRow _
& vbNewLine _
& "Next column = " & iCol
End Sub
'<<================

3) ALSO MORE IMPORTANTLY
How do I get a command button on a
UserForm
on sheet1 to automatically open a UserForm
on sheet2 to
enter new data.


In the first Userform's code module try something like:

'=============>>
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub
'<<============
 
R

rlashmore999

Hi R,


Try:

'=============>>
Private Sub Workbook_Open()
Userform1.Show
End Sub
'<<=============

This is workbook event code and should be pasted into
the workbook's ThisWorkbook module *not* a standard
module or a sheet module:

Right-click the Excel icon on the worksheet (or the icon
to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


It is invariably useful to post the problematic code.

However to return the next empty cell in column A and to
return the first empty column in row 1, try:

'================>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim iRow As Long
Dim iCol As Long

Set WB = Workbooks("MyBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

With SH
iRow = .Cells(.Rows.Count, "A").End(xlUp). _
Offset(1, 0).Row
iCol = .Cells(1, .Columns.Count).End(xlToLeft). _
Offset(0, 1).Column
End With

MsgBox Prompt:="Next row = " & iRow _
& vbNewLine _
& "Next column = " & iCol
End Sub
'<<================


In the first Userform's code module try something like:

'=============>>
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub
'<<============

THANKS FOR YOUR HELP

THIS IS WHAT HAPPENED NEXT

This is the code I've tried (I already have items in rows 1-4 and I
just want to add onto the next one)

Public Sub Tester()
Dim Fiddling As Workbook
Dim shtProductAdd As Worksheet
Dim iRow As Long
Dim iCol As Long
Set Fiddling = Workbooks("Fiddling.xls")
Set shtProductAdd = Fiddling.Worksheets("products")
With shtProductAdd
iRow = .Cells(.Rows.Count, "A").End(xlUp). _
Offset(1, 0).Row
iCol = .Cells(1, .Columns.Count).End(xlToLeft). _
Offset(0, 1).Column
End With
MsgBox Prompt:="Next row = " & iRow _
& vbNewLine _
& "Next column = " & iCol
End Sub

Private Sub NameButton_Click()
Dim strNameButton As String
Dim curBoxPrice As Currency
Dim intUnitNumber As Integer
Dim curSalePrice As Currency


Set shtProductAdd =
Application.Workbooks("Fiddling.xls").Worksheets("products")

strNameButton = InputBox("Please Enter Product Name")
shtProductAdd.Range("A5") = strNameButton
curBoxPrice = InputBox("Please Enter Box Price")
shtProductAdd.Range("B5") = curBoxPrice
intUnitNumber = InputBox("UNITS")
shtProductAdd.Range("C5") = intUnitNumber
curSalePrice = InputBox("Enter Sale Price")
shtProductAdd.Range("D5") = curSalePrice
End Sub
Private Sub ExitButon_Click()
Unload ProductForm
End Sub

Which returns me to only ever updating one single row (the 5 row
obviously)
The same as before I tried my latest bit of code to update the row and
move down
None of the code forms Ive tried from any text book has ever worked.
I know why I only do row 5 but Ive tried it with
ShtProductAdd (A:A")
You know what happened

Ive tried it with no data on the worksheet
and
ShtProductAdd("A")

Which returned

Method range of object worksheet failed

NEXT

To get a button called ClientButton2 on a userform on sheet 1

To open sheet 2 and go to a command button on the sheet which
Opens a new userform on sheet 2

I've tried

Private Sub ClientButton2_Click() 'this is on sheet1

Dim MenuButton As CommandButton
Me.Hide
MenuButton.Show 'command button on
sheet2

End Sub

Which gives me
Object variable or With block variable not set

Ive also got a listbox on the userform on sheet2 with this code


Private Sub ClientForm_Initialize() 'the userform on sheet2

Dim ListBox1 As ListBox
'select ............default list box
IstId.ListIndex = 0
'select default option button
'optTotal.Value = True
ListBox1.AddItem "M&M's plain (500g)"
ListBox1.AddItem "M&M's peanut (500g)"
ListBox1.AddItem "Cadbury Chocolate Bars (600g)"
End Sub




But none of my products shows in the listbox which remains empty



IF YOU COULD HELP ME WITH THIS I'D BE GRATEFUL

ID FATHER RATHER HAVE NEW NEWS EMAILED TO
(e-mail address removed) if possible rather than a newsgroup
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top