Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Logging Table with PrimaryKey


Code:
--------------------
Private Sub CommandButton2_Click()
CommandButton2_Click:

'Dim Variables
Dim i As Integer
Dim Product As Integer
Dim NextRow As Integer

'''''''''''''''''''''''''''''''
'If B1 = blank then...
If Sheets(1).Range("B1").Value = "" Then
'Bring up a MsgBox and request cell entry
MsgBox "Please enter a Member ID into highlighted cell B1", vbOKOnly, "Enter Member ID"
'End the Sub
Exit Sub
'''''''''''''''''''''''''''''''

Else

'If A14 : A13 = blank then...
If Sheets(1).Range("A4").Value = "" And Sheets(1).Range("A5").Value = "" And Sheets(1).Range("A6").Value = "" And Sheets(1).Range("A7").Value = "" And Sheets(1).Range("A8").Value = "" And Sheets(1).Range("A9").Value = "" And Sheets(1).Range("A10").Value = "" And Sheets(1).Range("A11").Value = "" And Sheets(1).Range("A12").Value = "" And Sheets(1).Range("A13").Value = "" Then
'Bring up a MsgBox requesting a product to be selected
MsgBox "Please select a product to purchase in Sheet1", vbOKOnly, "Select a Product"
'End the Sub if true
Exit Sub

Else
'''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''
' *** INSERT INTO SHEET 3 *** '
'''''''''''''''''''''''''''''''
'Set Variables
Product = 4
'Set up Loop
Do While Product <= 13
'Set Variables
NextRow = LastCell(Sheet3).Row
i = NextRow
MsgBox i

'ACTUAL CODING TO INSERT PRODUCT
If Sheets(1).Range("A" & Product).Value < "" Then
Sheets(3).Range("A" & i).Value = i - 1
Sheets(3).Range("B" & i).Value = Sheets(1).Range("B1").Value
End If
'END OF INSERTION

'Set Variables before looping
Product = Product + 1
'Loop
Loop


End If
End If
End Sub

Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%

' Error-handling is here in case there is not any
' data in the worksheet

On Error Resume Next

With ws

' Find the last real row

LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the last real column

LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

End With

' Finally, initialize a Range object variable for
' the last populated row.

Set LastCell = ws.Cells(LastRow&, LastCol%)

End Function



--------------------


I currently have this code, but it isn't working as I desire.

I have 4 sheets, but this part of my VBA is only concerning two of
them: Sheet1 and Sheet3.

In Sheet1 I have a table where the user can enter up to 10 products to
purchase goods. The user enters a "MemberID" into cell "B1". The user
then enters up to 10 product names from cell "A4" up to cell "A13". I
want the user to press a command button and the data will be sent to
Sheet3....

Sheet3 is essentially a logging table, where a log of all the products
are kept. If a product is in cell "A4" in sheet1 then it will be put
into the next available cell in Sheet3 in column "C". If there isn't
one then it will check cell "A4" and put it into Sheet3 and so on...
However, I am not concerned about that yet, if this first problem is
fixed then that can be fixed easily too. In column "A" in Sheet3 I
have a PurchaseID, essentially a primary key. I want this command
button to find the next blank cell in column "A" Sheet3, and then
insert into it the next integer in the PurchaseID sequence. I have had
a stab at it, but I cannot get it to work - what is going on? I can
only seem to get it to put the PurchaseID for the first product (into
row 2 Sheet3)and that is it.

If you still don't understand then post and say so.


--
Mario_Party
------------------------------------------------------------------------
Mario_Party's Profile: http://www.excelforum.com/member.php...o&userid=30925
View this thread: http://www.excelforum.com/showthread...hreadid=508371

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
Logging changes SPISO Excel Discussion (Misc queries) 0 May 12th 09 05:44 PM
Logging information SPISO Excel Worksheet Functions 0 April 22nd 09 02:16 PM
Logging into a website Jackblack1 Excel Discussion (Misc queries) 0 May 31st 06 05:27 PM
Logging activity George Foreman Excel Programming 5 February 2nd 05 05:28 PM
Change Logging Matt Jensen Excel Programming 0 December 20th 04 05:48 PM


All times are GMT +1. The time now is 09:34 PM.

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"