[Help] How can i make this vba function to goto.

MrGarrett

New Member
Joined
Nov 2, 2020
Messages
1
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
VBA Code:
Sub AddEntry()

        Dim sh As Worksheet
        Dim iRow As Long
        Dim LastRow As Long
        Set sh = ThisWorkbook.Sheets("Database")
        iRow = [Counta(Database!A:A)] + 1
        With sh
    
        .Cells(iRow, 1) = iRow - 1
        
        .Cells(iRow, 2).NumberFormat = "@"
        .Cells(iRow, 2) = frmForm.txtDate2.Value
        
        .Cells(iRow, 3) = frmForm.txtHCNumber3.Value
        
        .Cells(iRow, 4) = frmForm.txtName4.Value
        
        .Cells(iRow, 5).NumberFormat = "@"
        .Cells(iRow, 5) = frmForm.txtDOB5.Value
        
        .Cells(iRow, 6) = frmForm.txtAge6.Value
        
        .Cells(iRow, 7) = frmForm.cmbSourceReferral7.Value
        
        .Cells(iRow, 8) = frmForm.cmbSPA8.Value
        
        .Cells(iRow, 9).NumberFormat = "@"
        .Cells(iRow, 9) = frmForm.txtConsultDate9.Value
        
        .Cells(iRow, 10) = frmForm.txtTimeR10.Value
        
        .Cells(iRow, 11) = frmForm.cmbStatus11.Value
        
        .Cells(iRow, 12) = frmForm.txtTimeSeen12.Value
        
        .Cells(iRow, 13) = frmForm.cmbVisitOutcome13.Value
        
        .Cells(iRow, 14) = frmForm.txtTimeD14.Value
        
        .Cells(iRow, 15) = frmForm.cmbConsultant15.Value
        
        .Cells(iRow, 16) = frmForm.txtResident16.Value
        
        .Cells(iRow, 17) = frmForm.txtDiscussed17.Value
        
        .Cells(iRow, 18) = IIf(frmForm.optFemale.Value = True, "Female", "Male")
        
        .Cells(iRow, 19) = frmForm.cmbNation19.Value
        
        .Cells(iRow, 20) = frmForm.cmbPolice20.Value
        
        .Cells(iRow, 21) = frmForm.cmbKnown21.Value
        
        .Cells(iRow, 22) = frmForm.cmbSuicide22.Value
        
        .Cells(iRow, 23) = frmForm.txtReferred23.Value
        
        .Cells(iRow, 24) = frmForm.txtRemarks24.Value
        
        .Cells(iRow, 25) = Application.UserName
        
        .Cells(iRow, 26) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        
        .Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))

        End With

Code Above .Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))
i want to make it like this
if frmForm.txtTimeD14.Value = 0 "no value" go to Calculate Now Date
Calculate Now Date
.Cells(iRow, 27) = 24 * (Now - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value))
end if
if frmForm.txtTimeD14.Value = with value go to Calculate time discharged.
Calculate time discharged
.Cells(iRow, 27) = (DateValue(frmForm.txtDate2.Value) + TimeValue(frmForm.txtTimeD14.Value) - DateValue(frmForm.txtConsultDate9.Value) - TimeValue(frmForm.txtTimeR10.Value)) * 24
or any suggestion to make it work.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,507
Messages
6,125,201
Members
449,214
Latest member
mr_ordinaryboy

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