View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Is there a "Set sourceRange =" for all sheets in workbook

Your whim is my command... Here it is. Untested but I think it should work...

Public Sub CopyColumns()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngCopyTo As Range
Dim blnProceed As Boolean

Set wksCopyTo = Sheets("Main")
Set rngCopyTo = wksCopyTo.Range("IV1").End(xlToLeft).Offset(0, 2)
blnProceed = True

If rngCopyTo.Column < 1 Then
If MsgBox("You have already copied to the main sheet before. " & _
"Did you want to proceed?", vbYesNo, "Proceed") = vbYes Then
Set rngCopyTo = rngCopyTo.Offset(0, 1)
Else
blnProceed = False
End If
End If

If blnProceed = True Then
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name Then
wksCopyFrom.Range("D1").EntireColumn.Copy rngCopyTo
Set rngCopyTo = rngCopyTo.Offset(0, 1)
End If
Next wksCopyFrom
End If
End Sub


HTH

"Bill Metzgar via OfficeKB.com" wrote:

That works great too :-)
What I meant by: 1) starting it's copy at column 3 or C
is that the macro skips two columns before copying i.e. if the sheet is
empty the paste starts at column C instead of starting at column A then
subsequent runs leave two columns empty between previously pasted columns
and the newly pasted columns. None of that is a big deal though...
Thanks so much for your time!

Bill

--
Message posted via http://www.officekb.com