Trouble with macro to enter data in a table

6741bob

New Member
Joined
Jul 8, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I am trying to take data (both input and calculated) from one sheet and enter it to the next row on a table in another sheet and I keep getting the Error message "Run time error 1004'

Here is the data on the "input" sheet I am trying to store on "Sheet4"
Date2/23/2023mm/dd/yyyy
ValuesUnits
Height186Cms
186.00cmsstore this
Weight200lbs
90.9kgsstore this
Waist38inches
96.52cmsstore this
Hips36inches
91.44cmsstore this
Chest186Cms
186.00cmsstore this
Suprailiac15.00mms
15mmsstore this
% Body Fat22.8%%store this
RHR (7dy)55bpmstore this
BP-Systolic120mmhgstore this
BP-Diastolic80mmhgstore this
Waist/Height Ratio0.52Calculated, store this
BMI26.2Calculated, store this
Lean Body Mass154.4lbs
70.2kgsCalculated, store this

Here are the headings in row 1 on Sheet4 with Date in Column A
DateHeight cmsWeight kgsWaist cmsHips cmsChest cmsSuprailiac mms% Body FatRHR (7dy) bpmBP-Systolic mmhgBP-Diastolic mmhgWaist/Height RatioBMILean Body Mass kgs

Here is the macro that I am trying to run and the debugger indicates it is failing on the nextRow command. Any idea why this won't run?

Rich (BB code):
Sub Store_Measured_Data()
'takes data from input form worksheet and stores it in the next empty row on a worksheet

Dim sourceSheet As Worksheet
Dim dataSheet As Worksheet
Dim nextRow As Long

' Set sheet variables so we can use those rather than hardcoding
Set sourceSheet = Sheets("Input")
Set dataSheet = Sheets("Sheet4")

' get the next empty row from the data sheet
nextRow = dataSheet.Range("A" & dataSheet.Rows.Count).End(x1up).Offset(1).Row

'Input the form values into the data sheet
dataSheet.Cells(nextRow, 1).Value = sourceSheet.Range("e6").Value
dataSheet.Cells(nextRow, 2).Value = sourceSheet.Range("e8").Value
dataSheet.Cells(nextRow, 3).Value = sourceSheet.Range("e10").Value
dataSheet.Cells(nextRow, 4).Value = sourceSheet.Range("e12").Value
dataSheet.Cells(nextRow, 5).Value = sourceSheet.Range("e14").Value
dataSheet.Cells(nextRow, 6).Value = sourceSheet.Range("e16").Value
dataSheet.Cells(nextRow, 7).Value = sourceSheet.Range("e18").Value
dataSheet.Cells(nextRow, 8).Value = sourceSheet.Range("e20").Value
dataSheet.Cells(nextRow, 9).Value = sourceSheet.Range("e23").Value
dataSheet.Cells(nextRow, 10).Value = sourceSheet.Range("e25").Value
dataSheet.Cells(nextRow, 11).Value = sourceSheet.Range("e27").Value
dataSheet.Cells(nextRow, 12).Value = sourceSheet.Range("e29").Value
dataSheet.Cells(nextRow, 13).Value = sourceSheet.Range("e31").Value
dataSheet.Cells(nextRow, 14).Value = sourceSheet.Range("e34").Value

'Clear the form
sourceSheet.Range("e6").Value = ""
sourceSheet.Range("e8").Value = ""
sourceSheet.Range("e10").Value = ""
sourceSheet.Range("e12").Value = ""
sourceSheet.Range("e14").Value = ""
sourceSheet.Range("e16").Value = ""
sourceSheet.Range("e18").Value = ""
sourceSheet.Range("e20").Value = ""
sourceSheet.Range("e23").Value = ""
sourceSheet.Range("e25").Value = ""
sourceSheet.Range("e27").Value = ""
sourceSheet.Range("e29").Value = ""
sourceSheet.Range("e31").Value = ""
sourceSheet.Range("e34").Value = ""

End Sub
 
Last edited by a moderator:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

Any idea why this won't run?
Yes, you have used x1up not xlup
 
Upvote 0
Solution
I should have mentioned: Excel vba would have picked that error up for you if you had Option Explicit at the top of your module.
I would recommend always having that option set and vba will do it automatically for you if you make this setting in the vba window.

1677192859357.png
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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