Sunday 26 November 2017

excel - Need to run a Do While loop across multiple worksheets

I have been trying to run the same Do While loop function
across multiple worksheets in a workbook and compile the data in another worksheet. The
code works for the one worksheet that is specified but how do I get it to work across
the others that are in the workbook at the same time? Also worth mentioning that I only
want it to run on some of the worksheets not all that are in the workbook (sheets are
named as years - 2014, 2015 etc).



This is the
code



Sub
Total_Button1_Click()



Dim i As
Integer




Dim strSheetFrom As
String



Dim j As
Integer
Dim strSheetTo As String


i =
3
j = 2


strSheetFrom =
"2014"
strSheetTo = "Total"

Do While
Trim(Sheets(strSheetTo).Range("B" & CStr(j)).Text) <> ""
j = j +
2
Loop

Do While Trim(Sheets(strSheetFrom).Range("B" &
CStr(i)).Text) <> ""
If UCase(Trim(Sheets(strSheetFrom).Range("A" &
CStr(i)).Text)) = "Y" Then
Sheets(strSheetTo).Range("B" & j & ":G"
& j).Value = Sheets(strSheetFrom).Range("B" & i & ":G" &
i).Value

Sheets(strSheetTo).Range("H" & j & ":I" &
j).Value = Sheets(strSheetFrom).Range("I" & i & ":J" & i).Value

Sheets(strSheetTo).Range("J" & j & ":J" & j).Value =
Sheets(strSheetFrom).Range("L" & i & ":L" & i).Value

Sheets(strSheetTo).Range("K" & j & ":K" & j).Value =
Sheets(strSheetFrom).Range("Q" & i & ":Q" & i).Value

Sheets(strSheetTo).Range("L" & j & ":AH" & j).Value =
Sheets(strSheetFrom).Range("s" & i & ":AO" & i).Value
j = j +
1
End If
i = i + 1
Loop

MsgBox
"Total book
created"



End
Sub

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...