Need help

Beekman

Board Regular
Joined
Nov 7, 2008
Messages
64
Public Sub ShiftsCopyBlockTwice()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Dim ws1 As Worksheet<o:p></o:p>
Dim ws2 As Worksheet<o:p></o:p>
Dim ws3 As Worksheet<o:p></o:p>
Dim ws4 As Worksheet<o:p></o:p>
Dim ws5 As Worksheet<o:p></o:p>
Dim ws6 As Worksheet<o:p></o:p>
Dim iLastRow As Long<o:p></o:p>
Dim iRow As Long<o:p></o:p>
Dim iOutRow As Long<o:p></o:p>
<o:p></o:p>
Set ws1 = ThisWorkbook.Sheets("HEADER")<o:p></o:p>
Set ws2 = ThisWorkbook.Sheets("MONDAY")<o:p></o:p>
Set ws3 = ThisWorkbook.Sheets("TUESDAY")<o:p></o:p>
Set ws4 = ThisWorkbook.Sheets("WEDNESDAY")<o:p></o:p>
Set ws5 = ThisWorkbook.Sheets("THURSDAY")<o:p></o:p>
Set ws6 = ThisWorkbook.Sheets("FRIDAY")<o:p></o:p>
<o:p></o:p>
iLastRow = ws1.Range("B5").End(xlDown).Row<o:p></o:p>
<o:p></o:p>
iOutRow = 10<o:p></o:p>
For iRow = 5 To iLastRow<o:p></o:p>
iOutRow = iOutRow + 1<o:p></o:p>
ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")<o:p></o:p>
If ws1.Cells(iRow, "B").Value >= "4100" And ws1.Cells(iRow, "B").Value <= "4130" Then<o:p></o:p>
iOutRow = iOutRow + 1<o:p></o:p>
ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")<o:p></o:p>
End If<o:p></o:p>
Above is part of macro i am using and works fine.
I have on Header sheet a list in ColB from 4000 to 4130
Above macro relists these numbers in Col A in MONDAY with numbers
4100 to 4130 listed twice eg:-

4000
4001
4002
4003
4004 etc

4100
4100
4101
4101
4102
4102 etc

I have in "HEADER" Col C and Col E a list of times corresponding to the the list of numbers 4000 to 4130

I need to list Col C with the List of numbers 4000 to 4130 in "MONDAY" and Col E
with the second numbers 4100 to 4130 eg



4000 7:00 Time from Col C
4001 7:12 Time from Col C
4002 7:20
4100 8:05 Time from Colc
4100 14:30 Time from Col E
4102 8:10
4102 14:40

This Process will be repeated in "TUESDAY"to "FRIDAY"

Appreciate any help as I'm Hopeless at Macros but trying to learn
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This should do what you're requesting. I highlighted the changes in red so you can see what happened and try to understand what's going on.
Rich (BB code):
Public Sub ShiftsCopyBlockTwice()

  Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Dim ws3 As Worksheet
  Dim ws4 As Worksheet
  Dim ws5 As Worksheet
  Dim ws6 As Worksheet
  Dim iLastRow As Long
  Dim iRow As Long
  Dim iOutRow As Long

  Set ws1 = ThisWorkbook.Sheets("HEADER")
  Set ws2 = ThisWorkbook.Sheets("MONDAY")
  Set ws3 = ThisWorkbook.Sheets("TUESDAY")
  Set ws4 = ThisWorkbook.Sheets("WEDNESDAY")
  Set ws5 = ThisWorkbook.Sheets("THURSDAY")
  Set ws6 = ThisWorkbook.Sheets("FRIDAY")

  iLastRow = ws1.Range("B5").End(xlDown).Row

  iOutRow = 10
  For iRow = 5 To iLastRow
    iOutRow = iOutRow + 1
    ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")
    ws1.Cells(iRow, "C").Copy Destination:=ws2.Cells(iOutRow, "B")
    ws1.Cells(iRow, "B").Copy Destination:=ws3.Cells(iOutRow, "A")
    ws1.Cells(iRow, "C").Copy Destination:=ws3.Cells(iOutRow, "B")
    ws1.Cells(iRow, "B").Copy Destination:=ws4.Cells(iOutRow, "A")
    ws1.Cells(iRow, "C").Copy Destination:=ws4.Cells(iOutRow, "B")
    ws1.Cells(iRow, "B").Copy Destination:=ws5.Cells(iOutRow, "A")
    ws1.Cells(iRow, "C").Copy Destination:=ws5.Cells(iOutRow, "B")
    ws1.Cells(iRow, "B").Copy Destination:=ws6.Cells(iOutRow, "A")
    ws1.Cells(iRow, "C").Copy Destination:=ws6.Cells(iOutRow, "B")
    If ws1.Cells(iRow, "B").Value >= "4100" And ws1.Cells(iRow, "B").Value <= "4130" Then
      iOutRow = iOutRow + 1
      ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")
      ws1.Cells(iRow, "E").Copy Destination:=ws2.Cells(iOutRow, "B")
      ws1.Cells(iRow, "B").Copy Destination:=ws3.Cells(iOutRow, "A")
      ws1.Cells(iRow, "E").Copy Destination:=ws3.Cells(iOutRow, "B")
      ws1.Cells(iRow, "B").Copy Destination:=ws4.Cells(iOutRow, "A")
      ws1.Cells(iRow, "E").Copy Destination:=ws4.Cells(iOutRow, "B")
      ws1.Cells(iRow, "B").Copy Destination:=ws5.Cells(iOutRow, "A")
      ws1.Cells(iRow, "E").Copy Destination:=ws5.Cells(iOutRow, "B")
      ws1.Cells(iRow, "B").Copy Destination:=ws6.Cells(iOutRow, "A")
      ws1.Cells(iRow, "E").Copy Destination:=ws6.Cells(iOutRow, "B")
    End If
  Next iRow
End Sub

It could be that your code had more at the end. Your original post did not include the 'next iRow' and 'End Sub' lines.
 
Upvote 0
Thank you very much 'Moonfish'. Seems to work perfectly.

I guess I could add in extra colums to each Ws1,Ws2,Ws3 etc to fill in extra info into other columns .

I'll give it a try, again many thanks
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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