Inserting data within a named range..HELP

sulrich

New Member
Joined
Feb 15, 2005
Messages
20
I'm not an expert in vba in excel, however I would like some help. I have a worksheet with a named range called "Data". And, also on the worksheet I have a command button that initiates a userform. On that userform I have TextBox1.Value and TextBox2.Value...after the OK button is clicked within the userform, it inserts the data from the userform in the last row of that named range. I have part of the code to that adds the data to the worksheet, but the named range area stays the same. How do I get this to work. This is what I have so far:

Sheets("Sheet1").Range("A65536").End(xlUp)(2, 1).Value = TextBox1.Value
Sheets("Sheet1").Range("A65536").End(xlUp)(1, 2).Value = TextBox2.Value
Sheets("Sheet1").Range("A65536").End(xlUp)(1, 3).Value = TextBox3.Value

Thanks in advance... :cry: :cry:
 
Hi Jindon....
Can you explain the above code??? How do I use the code to insert into named range "DATA", without losing the format of the range???
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
sulrich,
try
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet, LastR As Long, LastR1 As Long, x As Long
Set ws = Sheets("sheet1")
With ws
    LastR = .Range("a10").End(xlUp).Row
    LastR1 = .Range("a11").End(xlDown).Row
    If .Range("a12") = "" Then: LastR1 = 11
    If UCase(Me.TextBox1) = "BLUE" Then
        x = LastR
        If Intersect(.Range("a" & x + 1), .Range("Data")) Is Nothing Then
            MsgBox "Sorry, Data is already full": Exit Sub
        End If
    Else
        x = LastR1
            If Intersect(.Range("a" & x + 1), .Range("Data1")) Is Nothing Then
                MsgBox "Sorry, Data1 is already full": Exit Sub
            End If
    End If
    For i = 1 To 3
        .Cells(x + 1, i).Value = Me.Controls(i)
    Next
    Set ws = Nothing
End With
End Sub
jindon
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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