Number Sequences

ellyna

Banned - Rules violations
Joined
Nov 29, 2020
Messages
89
Office Version
  1. 2013
Platform
  1. Windows
hi there may i ask regarding my number sequence ?
How do i change my script as i want it start from number 1 in excel database ?
Thank you

1608189432413.png


VBA Code:
Sub Submit()

    Dim sh As Worksheet
    Dim iRow As Long

    Set sh = ThisWorkbook.Sheets("Database")

    iRow = [Counta(Database!A:A)] + 3

    With sh

        .Cells(iRow, 1) = iRow - 1
        .Cells(iRow, 2) = frmForm.txtDate.Value
        .Cells(iRow, 3) = Now()
        .Cells(iRow, 3).NumberFormat = "dd-mm-yyyy | HH:mm:ss"
        .Cells(iRow, 4) = frmForm.cmbShift.Value
        .Cells(iRow, 5) = frmForm.cmbDepartment.Value
        .Cells(iRow, 6) = frmForm.txtLeader.Value
        .Cells(iRow, 7) = frmForm.txtAssistance.Value
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi again
change
VBA Code:
 iRow = [Counta(Database!A:A)] + 3
To
VBA Code:
 iRow = [Counta(Database!A:A)] + 1
 
Upvote 0
try
VBA Code:
    With sh
        If .Cells(iRow - 1, 1) = "" Then
            .Cells(iRow, 1) = 1
        Else
            .Cells(iRow, 1) = iRow - 3
        End If
        .Cells(iRow, 2) = frmForm.txtDate.Value

hth..
 
Upvote 0
try
VBA Code:
    With sh
        If .Cells(iRow - 1, 1) = "" Then
            .Cells(iRow, 1) = 1
        Else
            .Cells(iRow, 1) = iRow - 3
        End If
        .Cells(iRow, 2) = frmForm.txtDate.Value

hth..

1608191502312.png
 
Upvote 0
i would suggest providing your complete code along with the query. it would be helpful for others to test and edit your complete code.
 
Upvote 0
i would suggest providing your complete code along with the query. it would be helpful for others to test and edit your complete code.
VBA Code:
Sub Submit()

    Dim sh As Worksheet
    Dim iRow As Long

    Set sh = ThisWorkbook.Sheets("Database")

    iRow = [Counta(Database!A:A)] + 1

    With sh

       With sh
        If .Cells(iRow - 1, 1) = "" Then
            .Cells(iRow, 1) = 1
        Else
            .Cells(iRow, 1) = iRow - 3
        End If
        .Cells(iRow, 2) = frmForm.txtDate.Value
        .Cells(iRow, 3) = Now()
        .Cells(iRow, 3).NumberFormat = "dd-mm-yyyy | HH:mm:ss"
        .Cells(iRow, 4) = frmForm.cmbShift.Value
        .Cells(iRow, 5) = frmForm.cmbDepartment.Value
        .Cells(iRow, 6) = frmForm.txtLeader.Value
        .Cells(iRow, 7) = frmForm.txtAssistance.Value
        
        .Cells(iRow, 8) = frmForm.txtTargetMan.Value
        .Cells(iRow, 9) = frmForm.txtManNon.Value
        .Cells(iRow, 10) = frmForm.txtManBorrow.Value
        .Cells(iRow, 11) = frmForm.txtTotalMan.Value
        .Cells(iRow, 12) = frmForm.txtProduct.Value
        .Cells(iRow, 13) = frmForm.txtSetUp.Value
        .Cells(iRow, 14) = frmForm.txtTimeStart.Value
        .Cells(iRow, 15) = frmForm.txtTimeEnd.Value
        .Cells(iRow, 16) = frmForm.txtTotalHours.Value
        .Cells(iRow, 17) = frmForm.txtRemarks.Value

        .Cells(iRow, 18) = frmForm.txtMaterialIn.Value
        .Cells(iRow, 19) = frmForm.txtMaterialIn2.Value
        .Cells(iRow, 20) = frmForm.txtStartUp.Value
        .Cells(iRow, 22) = frmForm.txtStartUp2.Value
        .Cells(iRow, 22) = frmForm.txtRejection.Value
        .Cells(iRow, 23) = frmForm.txtRejection2.Value
        .Cells(iRow, 24) = frmForm.txtWpcs.Value
        .Cells(iRow, 25) = frmForm.txtWpcs2.Value
        .Cells(iRow, 26) = frmForm.txtWkg.Value
        .Cells(iRow, 27) = frmForm.txtWkg2.Value
        .Cells(iRow, 28) = frmForm.txtWpercent.Value
        .Cells(iRow, 29) = frmForm.txtWpercent2.Value
        .Cells(iRow, 30) = frmForm.txtPOpcs.Value
        .Cells(iRow, 31) = frmForm.txtPOpcs2.Value
        .Cells(iRow, 32) = frmForm.txtPOkg.Value
        .Cells(iRow, 33) = frmForm.txtPOkg2.Value
        
        .Cells(iRow, 34) = frmForm.txtTotalMaterial.Value
        .Cells(iRow, 35) = frmForm.txtTotalMaterial2.Value
        .Cells(iRow, 36) = frmForm.txtMachineCap.Value
        .Cells(iRow, 37) = frmForm.txtMachineCap2.Value
        .Cells(iRow, 38) = frmForm.txtTotalOutkg.Value
        .Cells(iRow, 39) = frmForm.txtTotalOutkg2.Value
        .Cells(iRow, 40) = frmForm.txtTotalOutpcs.Value
        .Cells(iRow, 41) = frmForm.txtTotalOutpcs2.Value
        .Cells(iRow, 42) = frmForm.txtWtkg.Value
        .Cells(iRow, 43) = frmForm.txtWtkg2.Value
        .Cells(iRow, 44) = frmForm.txtWtpcs.Value
        .Cells(iRow, 45) = frmForm.txtWtpcs2.Value
        .Cells(iRow, 46) = frmForm.txtCB.Value
        .Cells(iRow, 47) = frmForm.txtCB2.Value
        .Cells(iRow, 48) = frmForm.txtCA.Value
        .Cells(iRow, 49) = frmForm.txtCA2.Value
        .Cells(iRow, 50) = frmForm.txtDC.Value
        .Cells(iRow, 51) = frmForm.txtDC2.Value
    
    End With
    
End Sub
 
Upvote 0
this is the culprit.
With sh With sh If .Cells(iRow - 1, 1) = "" Then .Cells(iRow, 1) = 1
try
VBA Code:
Sub Submit()

    Dim sh As Worksheet
    Dim iRow As Long

    Set sh = ThisWorkbook.Sheets("Database")

    iRow = [Counta(Database!A:A)] + 1

       With sh
        If .Cells(iRow - 1, 1) = "" Then
            .Cells(iRow, 1) = 1
        Else
            .Cells(iRow, 1) = iRow - 3
        End If
        .Cells(iRow, 2) = frmForm.txtDate.Value
        .Cells(iRow, 3) = Now()
        .Cells(iRow, 3).NumberFormat = "dd-mm-yyyy | HH:mm:ss"
        .Cells(iRow, 4) = frmForm.cmbShift.Value
        .Cells(iRow, 5) = frmForm.cmbDepartment.Value
        .Cells(iRow, 6) = frmForm.txtLeader.Value
        .Cells(iRow, 7) = frmForm.txtAssistance.Value
        
        .Cells(iRow, 8) = frmForm.txtTargetMan.Value
        .Cells(iRow, 9) = frmForm.txtManNon.Value
        .Cells(iRow, 10) = frmForm.txtManBorrow.Value
        .Cells(iRow, 11) = frmForm.txtTotalMan.Value
        .Cells(iRow, 12) = frmForm.txtProduct.Value
        .Cells(iRow, 13) = frmForm.txtSetUp.Value
        .Cells(iRow, 14) = frmForm.txtTimeStart.Value
        .Cells(iRow, 15) = frmForm.txtTimeEnd.Value
        .Cells(iRow, 16) = frmForm.txtTotalHours.Value
        .Cells(iRow, 17) = frmForm.txtRemarks.Value

        .Cells(iRow, 18) = frmForm.txtMaterialIn.Value
        .Cells(iRow, 19) = frmForm.txtMaterialIn2.Value
        .Cells(iRow, 20) = frmForm.txtStartUp.Value
        .Cells(iRow, 22) = frmForm.txtStartUp2.Value
        .Cells(iRow, 22) = frmForm.txtRejection.Value
        .Cells(iRow, 23) = frmForm.txtRejection2.Value
        .Cells(iRow, 24) = frmForm.txtWpcs.Value
        .Cells(iRow, 25) = frmForm.txtWpcs2.Value
        .Cells(iRow, 26) = frmForm.txtWkg.Value
        .Cells(iRow, 27) = frmForm.txtWkg2.Value
        .Cells(iRow, 28) = frmForm.txtWpercent.Value
        .Cells(iRow, 29) = frmForm.txtWpercent2.Value
        .Cells(iRow, 30) = frmForm.txtPOpcs.Value
        .Cells(iRow, 31) = frmForm.txtPOpcs2.Value
        .Cells(iRow, 32) = frmForm.txtPOkg.Value
        .Cells(iRow, 33) = frmForm.txtPOkg2.Value
        
        .Cells(iRow, 34) = frmForm.txtTotalMaterial.Value
        .Cells(iRow, 35) = frmForm.txtTotalMaterial2.Value
        .Cells(iRow, 36) = frmForm.txtMachineCap.Value
        .Cells(iRow, 37) = frmForm.txtMachineCap2.Value
        .Cells(iRow, 38) = frmForm.txtTotalOutkg.Value
        .Cells(iRow, 39) = frmForm.txtTotalOutkg2.Value
        .Cells(iRow, 40) = frmForm.txtTotalOutpcs.Value
        .Cells(iRow, 41) = frmForm.txtTotalOutpcs2.Value
        .Cells(iRow, 42) = frmForm.txtWtkg.Value
        .Cells(iRow, 43) = frmForm.txtWtkg2.Value
        .Cells(iRow, 44) = frmForm.txtWtpcs.Value
        .Cells(iRow, 45) = frmForm.txtWtpcs2.Value
        .Cells(iRow, 46) = frmForm.txtCB.Value
        .Cells(iRow, 47) = frmForm.txtCB2.Value
        .Cells(iRow, 48) = frmForm.txtCA.Value
        .Cells(iRow, 49) = frmForm.txtCA2.Value
        .Cells(iRow, 50) = frmForm.txtDC.Value
        .Cells(iRow, 51) = frmForm.txtDC2.Value
    
    End With
    
End Sub
 
Upvote 0
this is the culprit.

try
VBA Code:
Sub Submit()

    Dim sh As Worksheet
    Dim iRow As Long

    Set sh = ThisWorkbook.Sheets("Database")

    iRow = [Counta(Database!A:A)] + 1

       With sh
        If .Cells(iRow - 1, 1) = "" Then
            .Cells(iRow, 1) = 1
        Else
            .Cells(iRow, 1) = iRow - 3
        End If
        .Cells(iRow, 2) = frmForm.txtDate.Value
        .Cells(iRow, 3) = Now()
        .Cells(iRow, 3).NumberFormat = "dd-mm-yyyy | HH:mm:ss"
        .Cells(iRow, 4) = frmForm.cmbShift.Value
        .Cells(iRow, 5) = frmForm.cmbDepartment.Value
        .Cells(iRow, 6) = frmForm.txtLeader.Value
        .Cells(iRow, 7) = frmForm.txtAssistance.Value
       
        .Cells(iRow, 8) = frmForm.txtTargetMan.Value
        .Cells(iRow, 9) = frmForm.txtManNon.Value
        .Cells(iRow, 10) = frmForm.txtManBorrow.Value
        .Cells(iRow, 11) = frmForm.txtTotalMan.Value
        .Cells(iRow, 12) = frmForm.txtProduct.Value
        .Cells(iRow, 13) = frmForm.txtSetUp.Value
        .Cells(iRow, 14) = frmForm.txtTimeStart.Value
        .Cells(iRow, 15) = frmForm.txtTimeEnd.Value
        .Cells(iRow, 16) = frmForm.txtTotalHours.Value
        .Cells(iRow, 17) = frmForm.txtRemarks.Value

        .Cells(iRow, 18) = frmForm.txtMaterialIn.Value
        .Cells(iRow, 19) = frmForm.txtMaterialIn2.Value
        .Cells(iRow, 20) = frmForm.txtStartUp.Value
        .Cells(iRow, 22) = frmForm.txtStartUp2.Value
        .Cells(iRow, 22) = frmForm.txtRejection.Value
        .Cells(iRow, 23) = frmForm.txtRejection2.Value
        .Cells(iRow, 24) = frmForm.txtWpcs.Value
        .Cells(iRow, 25) = frmForm.txtWpcs2.Value
        .Cells(iRow, 26) = frmForm.txtWkg.Value
        .Cells(iRow, 27) = frmForm.txtWkg2.Value
        .Cells(iRow, 28) = frmForm.txtWpercent.Value
        .Cells(iRow, 29) = frmForm.txtWpercent2.Value
        .Cells(iRow, 30) = frmForm.txtPOpcs.Value
        .Cells(iRow, 31) = frmForm.txtPOpcs2.Value
        .Cells(iRow, 32) = frmForm.txtPOkg.Value
        .Cells(iRow, 33) = frmForm.txtPOkg2.Value
       
        .Cells(iRow, 34) = frmForm.txtTotalMaterial.Value
        .Cells(iRow, 35) = frmForm.txtTotalMaterial2.Value
        .Cells(iRow, 36) = frmForm.txtMachineCap.Value
        .Cells(iRow, 37) = frmForm.txtMachineCap2.Value
        .Cells(iRow, 38) = frmForm.txtTotalOutkg.Value
        .Cells(iRow, 39) = frmForm.txtTotalOutkg2.Value
        .Cells(iRow, 40) = frmForm.txtTotalOutpcs.Value
        .Cells(iRow, 41) = frmForm.txtTotalOutpcs2.Value
        .Cells(iRow, 42) = frmForm.txtWtkg.Value
        .Cells(iRow, 43) = frmForm.txtWtkg2.Value
        .Cells(iRow, 44) = frmForm.txtWtpcs.Value
        .Cells(iRow, 45) = frmForm.txtWtpcs2.Value
        .Cells(iRow, 46) = frmForm.txtCB.Value
        .Cells(iRow, 47) = frmForm.txtCB2.Value
        .Cells(iRow, 48) = frmForm.txtCA.Value
        .Cells(iRow, 49) = frmForm.txtCA2.Value
        .Cells(iRow, 50) = frmForm.txtDC.Value
        .Cells(iRow, 51) = frmForm.txtDC2.Value
   
    End With
   
End Sub
I've tried it and it still not working. Here i attach my link of dropbox.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,254
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top