View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
brentm brentm is offline
external usenet poster
 
Posts: 35
Default Copy data from one tab to another based on cell value on one

Rick,

Thanks, but here is the code I have. When the macro is run, nothing
happens. I do not get any errors either. When I run to debug, there are no
problems found. What am I missing?

Sub Copy_SolutionB()
'
' Copy_SolutionB Macro
'

'
Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name = Format(Range("G10").Value, "mmmm d") Then
Range("C2:E8").Select
Selection.Copy
Sheets("Invoice").Select
Range("C14:E20").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("C14:E14,C16:E16,C18:E18,C20:E20").Select
Range("C20").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
End If
Exit For
Next

End Sub

Thanks a ton for your expert help!
Brent


"Rick Rothstein (MVP - VB)" wrote:

You will use a structure similar to this...

Dim WS As Worksheet
For Each WS In Worksheets
If WS.Name = Format(Range("C10").Value, "mmmm d") Then
'
' << Do whatever here
'
Exit For
End If
Next

Put the code you say you know how to do where indicated.

Rick


"brentm" wrote in message
...
I have a spreadsheet where each tab represents 1 week. the tabs are named
based on the week ending date that tab covers - "June 25", "July 2", etc.
There is a master tab named "Invoice" with the period ending date residing
in
cell C10. Is there a way I can have a macro go to the appropriate tab
based
on the date entered in C10 on the "Invoice" tab? I need the macro to copy
over specific information, which I can do, but I wanted the macro to
automatically look at the value in C10 on "Invoice", then go get the
information from the appropriate tab that corrosponds to that cell value.
Anyone have any ideas?