Loop through ws using userform

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
I have a userform to input data into the same row in each worksheet for each sheet.
I have 26 worksheets in my workbook us there a way of looping through this line of code??

Each textbox from 2 is associated with a worksheet. Eg. Sheet2 = Me.TextBox2

x = Me.TextBox + 7 'this is week no me.textbox1
For i = 2 to 27
Sheet(i).Cells(x ,4).value = Me.TextBox(i)
Next i

This does not work. Any help please.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What exactly does this mean, especially "no"?
x = Me.TextBox + 7 'this is week no me.textbox1

And if all rows are the same on every sheet, why are you bothering with a variable for x. If it's row 38 then why not just say
Cells(38, 4) instead of Cells(x, 4) or simpler, Range("D38").

And why do you say "the same row" if it looks like it is the same cell based on that part of your code.
 
Upvote 0
Try:
Code:
For i = 2 To 27
    Sheet(i - 1).Cells(x, 4).Value = Me.Controls("TextBox" & i).Text
Next i
 
Upvote 0
Hi Tom,

I have put x because the row will change a long with the week number (wk no)
e.g.
x = Me.TextBox1 + 7
if x is Wk 1 then it will be row 8 to put data into.

:)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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