Userform must always display data on Sheet1 while on any other sheet.,..

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
918
Office Version
  1. 365
Platform
  1. Windows
This code displays data in Userform1 on the active sheet(in the background [showmodal = false]
Code:
Private Sub UserForm_Initialize()

currentrow = 2  'currentrow is a global variable of type Long

lastrow = Sheets("REGISTER").Range("A" & Rows.count).End(xlUp).Row

TextBox1 = Cells(currentrow, 1)
TextBox2 = Cells(currentrow, 2)
TextBox3 = Cells(currentrow, 3)
TextBox4 = Cells(currentrow, 6)
TextBox5 = Cells(currentrow, 7)
Userform1 is fired from a QAT button with Sheet2 or any sheet being the Activesheet. The problem is, the Textboxes are populated with data from Sheet2 or the Activesheet. I don't want that. I want Userform1 to ALWAYS display data from Sheet1 regardless of which sheet I'm on

Another way of saying this is, every time I change the sheet and click the QAT button, it fills the textboxes with data from that active sheet, which gives meaningless information. How do I keep Userform1 to always display data from Sheet1 ?

Thanks for anyone's help.

cr
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How about
Code:
Private Sub UserForm_Initialize()

currentrow = 2  'currentrow is a global variable of type Long
With Sheets("REGISTER")
   Lastrow = .Range("A" & Rows.Count).End(xlUp).Row
   
   TextBox1 = .Cells(currentrow, 1)
   TextBox2 = .Cells(currentrow, 2)
   TextBox3 = .Cells(currentrow, 3)
   TextBox4 = .Cells(currentrow, 6)
   TextBox5 = .Cells(currentrow, 7)
End With
 
Upvote 0
How about
Code:
Private Sub UserForm_Initialize()

currentrow = 2  'currentrow is a global variable of type Long
With Sheets("REGISTER")
   Lastrow = .Range("A" & Rows.Count).End(xlUp).Row
   
   TextBox1 = .Cells(currentrow, 1)
   TextBox2 = .Cells(currentrow, 2)
   TextBox3 = .Cells(currentrow, 3)
   TextBox4 = .Cells(currentrow, 6)
   TextBox5 = .Cells(currentrow, 7)
End With

Thanks Fluff - putting the same code within a With-End With block still does not work. The userform textboxes are filled with data from the active sheet. There has to be some inherent flaw in this code that's causing the Userform not to always use the data on the REGISTER sheet(which is what I want) and NOT the active sheet that appears on the screen
This seems way too simple to give such a problem. What are we missing here ?

Thks, cr
 
Upvote 0
Did you use the code I supplied, or modify your own code?
If the latter did you put the . infront of Cells?
 
Upvote 0
Did you use the code I supplied, or modify your own code?
If the latter did you put the . infront of Cells?

This is the code that does not work
Code:
currentrow = 2  'currentrow is a global variable of type Long
With Sheets("REGISTER")
lastrow = Range("A" & Rows.count).End(xlUp).Row
TextBox1 = .Cells(currentrow, 1)
TextBox2 = .Cells(currentrow, 2)
TextBox3 = .Cells(currentrow, 3)
TextBox4 = .Cells(currentrow, 6)
TextBox5 = .Cells(currentrow, 7)
End With

cr
 
Upvote 0
This is the code that does not work
Code:
currentrow = 2  'currentrow is a global variable of type Long
With Sheets("REGISTER")
lastrow = Range("A" & Rows.count).End(xlUp).Row
TextBox1 = .Cells(currentrow, 1)
TextBox2 = .Cells(currentrow, 2)
TextBox3 = .Cells(currentrow, 3)
TextBox4 = .Cells(currentrow, 6)
TextBox5 = .Cells(currentrow, 7)
End With

cr
...oops made a stupid mistake...your code works perfectly. Embarrassed.
disregard last reply
cr
 
Upvote 0
Deleted, seen post#6
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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