Send data from userform to named range

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a userform that is used to collect something like 75 pieces of data, which are then sent to the main form with code like this:

Code:
ws.Cells(lRow, 4).Value = Me.txtRep1
etc.

After the data is sent to the form, I have some more code which then parses it out into 5 individual named ranges for easier import into an Access database. It's working pretty well. So well, in fact, that now Management wants to expand it to include more data points. I am dreading the grief I will go through, because I will have to offset each and every cell value manually in the code. Is there a way to reference the named range in the code, so at least I can keep the destination fields clear in my mind while doing the job?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Show us some more of your code where you are taking the data from the Userform and placing it in the range you want. If your dealing with a lot of values we should be able to make a loop that would keep you from having to write a lot of code assuming you have some relationship for example textbox1 data goes in cells(1,1) and textbox2 data goes into cells(1,2).
 
Upvote 0
Hello, and thanks for your reply. Here is code for one of the named ranges:
Code:
'--------ClinicData--------
ws.Cells(lRow, 1).Value = Format(Me.TxtTxID & (lRow - 2), "0")
ws.Cells(lRow, 2).Value = Me.txtClinic
ws.Cells(lRow, 3).Value = Me.txtSurgeon
ws.Cells(lRow, 4).Value = Me.txtRep1
ws.Cells(lRow, 5).Value = Me.txtRep2


If Me.txtSN > 4 Then
    ws.Cells(lRow, 6).Value = Right(Me.txtSN, 4)
Else: ws.Cells(lRow, 6).Value = Me.txtSN
End If

ws.Cells(lRow, 7).Value = Me.txtSW
ws.Cells(lRow, 8).Value = Me.cboPhaco
ws.Cells(lRow, 9).Value = Format(Me.txtDate, "dd-mmm-yyyy")
where ws is the destination worksheet and lRow is the last row. In this case the named range is "aClinicData" . Maybe you can see my dilemma... If I have to add two items to this, then each and every cell reference after the inserted columns have to be changed by two... I was thinking if the reference could be made to the named range when moving the data it would be much easier to keep straight in my mind.
I have this code for naming the ranges dynamically:
Code:
Sub Name_Ranges()


Sheets("Export").Unprotect Password:="CataractData"
ThisWorkbook.Names.Add Name:="aClinicData", _
    RefersTo:=Sheets("Export").Range("A1:I" & Sheets("Export").Range("A65535").End(xlUp).Row)

End Sub
 
Upvote 0
I think this may beyond my knowledge base. Hopefully someone else here at Mr. Excel will be able to help you.
 
Upvote 0

Forum statistics

Threads
1,215,752
Messages
6,126,672
Members
449,327
Latest member
John4520

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