Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

problem replace for headers when copy data from userform


Hi Guys ,

I  need to  know  and  fix problem  copy  data from  userform .

it  should  start  from  row2 when  copy  data but  it  will replace for  some  headers in row  1 when  select optionbuttons and  fill textboxes .




Selected Answer

Hi Alaa

The problem is that you forgot to define variable lr (last row). Do this just after the opening With statement:

With ws

       lr = .Range("A" & Rows.Count).End(xlUp).Row

Notice that I didn't say lr=ws.Range... (since the With means you don't have to). 

If you want to declare the variable, use Dim lr as Long



Hi john ,
sorry  for  this  stupid mistake !
thanks very much
Alaa (rep: 30) May 21, '23 at 10:10 am
No problem Alaa, thanks for selecting my Answer. We all make mistakes- to err is to be human (and I'm known for my humanity!) 
John_Ru (rep: 6232) May 21, '23 at 11:42 am
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login