Next available row

dreimer

New Member
Joined
May 13, 2019
Messages
11
Please help before I go mad.

I am working on a patient assessment form - there's going to be approximately 80-90 columns of data in each row when it's done. The first part is patient demographics. All I am trying to do is get the next available row. I can't get past the run time error. "Method Range of Object Global Failed




Private Sub CB1Save_Click()
Sheets("Sheet2").Activate
'Save to Worksheet
Dim irow As Long
irow = Range("B" & Rows.Count).End(xlUp).Row + 1

Range("A" & irow) = DemographicPatientName.Value
Range("B" & irow) = DemographicDOB.Value
Range("C" & irow) = DemographicAge.Value
Range("D" & irow) = DemographicMonitor.Value
Range("E" & irow) = DemographicDeviceNumber.Value
Range("F" & irow) = DemographicStartDate.Value
Range("G" & irow) = DemographicEndDate.Value
 
Re: Next avaialable row

running your code the mesgBox

'lRow = Cells.Find(What:="*", _
' After:=Range("A1"), _
' LookAt:=xlPart, _
' LookIn:=xlFormulas, _
' SearchOrder:=xlByRows, _
' SearchDirection:=xlPrevious, _
' MatchCase:=False).Row
' MsgBox "Last Row: " & lRowwas 4
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Re: Next avaialable row

sorry - new to this

your code - the mesgbox read 4
another code i was trying gave me "Last Row 3"
'lRow = Cells.Find(What:="*", _
' After:=Range("A1"), _
' LookAt:=xlPart, _
' LookIn:=xlFormulas, _
' SearchOrder:=xlByRows, _
' SearchDirection:=xlPrevious, _
' MatchCase:=False).Row
' MsgBox "Last Row: " & lRow
 
Upvote 0
Code:
Private Sub CB1Save_Click()


'Save to Worksheet
Dim irow As Long
Dim ws As Worksheet


Set ws = Sheets("Sheet2")


irow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1


ws.Range("A" & irow) = ws.Range("DemographicDOB")
ws.Range("B" & irow) = ws.Range("DemographicDOB")
ws.Range("C" & irow) = ws.Range("DemographicAge")
ws.Range("D" & irow) = ws.Range("DemographicMonitor")
ws.Range("E" & irow) = ws.Range("DemographicDeviceNumber")
ws.Range("F" & irow) = ws.Range("DemographicStartDate")
ws.Range("G" & irow) = ws.Range("DemographicEndDate")


End Sub
 
Upvote 0
Re: Next avaialable row

Can you please post the code that you are currently using?
It's very difficult to help when you change it, without telling us. ;)

Your original code had irow, what you have just posted has lrow
 
Last edited:
Upvote 0
Code:
Private Sub CB1Save_Click()


'Save to Worksheet
Dim irow As Long
Dim ws As Worksheet


Set ws = Sheets("Sheet2")


irow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1


ws.Range("A" & irow) = ws.Range("DemographicDOB")
ws.Range("B" & irow) = ws.Range("DemographicDOB")
ws.Range("C" & irow) = ws.Range("DemographicAge")
ws.Range("D" & irow) = ws.Range("DemographicMonitor")
ws.Range("E" & irow) = ws.Range("DemographicDeviceNumber")
ws.Range("F" & irow) = ws.Range("DemographicStartDate")
ws.Range("G" & irow) = ws.Range("DemographicEndDate")


End Sub
 
Upvote 0
Re: Next avaialable row

Here's where its at - now
Private Sub CB1Save_Click()
Sheets("Sheet 2").Activate
Dim lRow As Long
Dim lCol As Long
irow = Range("B" & Rows.Count).End(xlUp).Row + 1
MsgBox irow


Range("A" & irow) = DemographicPatientName.Value
Range("B" & irow) = DemographicDOB.Value
Range("C" & irow) = DemographicAge.Value
Range("D" & irow) = DemographicMonitor.Value
Range("E" & irow) = DemographicDeviceNumber.Value
Range("F" & irow) = DemographicStartDate.Value
Range("G" & irow) = DemographicEndDate.Value
Range("H" & irow) = DemographicPtActivate.Value
Range("I" & irow) = DemographicPtActivateSymp.Value
Range("J" & irow) = DemographicAuto.Value
Range("K" & irow) = DemographicAutoSymp.Value
Range("L" & irow) = DemographicZip.Value
Range("M" & irow) = DemographicLAT.Value
Range("N" & irow) = DemographicCity.Value
Range("O" & irow) = DemographicLONG.Value
Range("L" & irow) = DemographicAddressNow.Value
Range("M" & irow) = DemographicState.Value
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Upvote 0
No thank you - i just could not get why it wasnt working because i copied it from another form that worked???
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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