Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
excel VBA - for loop for several sheets
Hi
I want to do loops on these line of codes for Sheet1 and Sheet2. Is there a way I could make the Sheet number as a variable e.g. Sheet(x).cells(Counter, 1)? Private Sub GCDButton_Click() For Counter = 1 To CipherTextBox.TextLength Sheet1.Cells(Counter, 1) = Counter Sheet1.Cells(Counter, 2) = Mid(CipherTextBox.Text, Counter 3) Sheet2.Cells(Counter, 1) = Counter Sheet2.Cells(Counter, 2) = Mid(CipherTextBox.Text, Counter 4) Next Columns("A:B").Select Selection.Sort Key1:=Range("B1"), Order1:=xlAscending Key2:=Range("A1") _ , Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1 MatchCase:= _ False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal DataOption2 _ :=xlSortNormal 'Find distance For I = 1 To CipherTextBox.TextLength If Sheet1.Cells(I, 2) = Sheet1.Cells(I + 1, 2) Then Sheet1.Cells(I, 3) = Sheet1.Cells(I, 1) - Sheet1.Cells(I 1, 1) Else Sheet1.Cells(I, 3) = "" End If Next 'Find Greatest Common Divisor (GCD) Worksheets("Sheet1").Activate Range("D1").Select ActiveCell.FormulaR1C1 = "=GCD(RC[-1]:R[" LTrim(Str(CipherTextBox.TextLength)) + "]C[-1])" Range("D2").Select Thanks in advance Did -- Message posted from http://www.ExcelForum.com |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Loop all Sheets not working. | New Users to Excel | |||
Loop through varible list of sheets | Excel Discussion (Misc queries) | |||
Loop across Sheets and number of sheets | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming | |||
Loop through sheets, deselect charts | Excel Programming |