Adrac

Active Member
Joined
Feb 13, 2014
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have this script for moving data from a userform to a TABLE on a sheet called Main. This is not working as the line "LR = Main.Cells(Rows.Count, "A").End(x1up).Row" keeps stopping.

Can you have a look and let me know if you can see anything wrong.

SideNote: I would also like a code to create a formula "=VLOOKUP(B2,Config!$A$2:$B$5,2,0)" to go into column F

Code:
Private Sub CommandButton1_Click()
Dim LR As Integer, Main As Worksheet
Set Main = ThisWorkbook.Worksheets("Main")
LR = Main.Cells(Rows.Count, "A").End(x1up).Row
If LR = 2 And Cells(LR, "A").Value = "" Then
    LR = LR
Else
    LR = LR + 1
End If
    
Main.Cells(LR, "A").Value = TextBox1.Value
Main.Cells(LR, "B").Value = ComboBox1.Value
Main.Cells(LR, "C").Value = TextBox2.Value
Main.Cells(LR, "D").Value = ComboBox2.Value
Main.Cells(LR, "E").Value = CheckBox1.Value
Main.Cells(LR, "G").Value = TextBox3.Value

TextBox1.Value = ""
ComboBox1.Value = ""
TextBox2.Value = ""
ComboBox2.Value = ""
CheckBox1.Value = ""
TextBox3.Value = ""
New_Account.Hide
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Morning, if this is a direct copy of your code - "LR = Main.Cells(Rows.Count, "A").End(x1up).Row" That number 1 in there needs to be a lowercase "L"

Code:
Main.Cells(LR, "F").formula = "=VLOOKUP(B2,Config!$A$2:$B$5,2,0)"

will put the formula in. Have fun!
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,987
Members
449,480
Latest member
yesitisasport

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