loop is driving me "nuts"

KatyJohn

New Member
Joined
Jan 25, 2009
Messages
41
Hey Folks

I'm having a difficult time getting a loop to work. Problem is that I can't resolve the loops with a proper ending and this is stopping me from stepping through the macro to see if it actually works.

The objective of this macro is to loop through 4 or 5 sheets in a workbook(NewOpenFile). The macro should check a cell ("C3") in each sheet and if the cell contains the text "Company" another array loop copies a column of cell text from a sheet in (NewOpenFile) that meets the criteria and copies the text to a master workbook call "2009 Quote Form"

Here is the code:

Private Sub CommandButtonModHead_Click()

Dim NewOpenFile As String
Dim FromRng, ToRng
Dim i As Integer
Dim x As Integer
NewOpenFile = Range("BG21")

Workbooks(NewOpenFile).Activate
For i = 1 To Workbooks(NewOpenFile).Sheets.Count

If Workbooks(NewOpenFile).Sheets(i) = True Then

For Each sht In Workbooks(NewOpenFile).Sheets
If Range("C3") = "company" Then
With sht



FromRng = Array("D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10")
ToRng = Array("C25", "C26", "C27", "C28", "C29", "C30", "C31", "C32")
For x = LBound(FromRng) To UBound(FromRng)

Workbooks(NewOpenFile).Sheets("Module Number Entry").Range(FromRng(x)).Copy
Workbooks("2009 Quote Form.xlsm").Sheets(i).Range(ToRng(x)).PasteSpecial Paste:=xlPasteValues



End With


Next x

End If

Sheets(i).Range("C3") = " "

Next

End Sub



Thanks in advance
katyjohn
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I had the wrong copy and paste sequence.

Workbooks(NewOpenFile).Sheets(i).Range(FromRng(x)).Copy
Workbooks("2009 Quote Form.xlsm").Sheets("Module Number Entry").Range(ToRng(x)).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Katy

Why are you looping through the worksheets twice?

And why are the to/from ranges stored in arrays?
 
Upvote 0

Forum statistics

Threads
1,203,316
Messages
6,054,702
Members
444,742
Latest member
jmartin9247

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