Re asking help

Beekman

Board Regular
Joined
Nov 7, 2008
Messages
64
Dim ws1 As Worksheet<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><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>
Next iRow<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>
Next iRow<o:p></o:p>
This macrow works for me in duplicating 4100-4300 eg

4100
4100
4101
4101
etc
but some of the numbers end in a letter eg

4110W
4117M
etc
the macro does'nt see this as a number between 4100-4300 and won't duplicate them.
Can anyone come up with a modification of above macro so it will duplicate both number and number with letter ending.

Thanks for any help
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi Beekman,

Obviously largely untested, but see how this goes:

Code:
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")
If ws1.Val(Left(Cells(iRow, "B"), 4)) >= 4100 And ws1.Val(Left(Cells(iRow, "B"), 4)) <= 4130 Then
iOutRow = iOutRow + 1
ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")
End If
Next iRow
iOutRow = 10
For iRow = 5 To iLastRow
iOutRow = iOutRow + 1
ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")
If ws1.Val(Left(Cells(iRow, "B"), 4)) >= 4100 And ws1.Val(Left(Cells(iRow, "B"), 4)) <= 4130 Then
iOutRow = iOutRow + 1
ws1.Cells(iRow, "B").Copy Destination:=ws2.Cells(iOutRow, "A")
End If
Next iRow

HTH

Robert
 
Upvote 0
Try this line of code...

Code:
If Val(Left(ws1.Cells(10, "A"), 4)) >= 4100 And Val(Left(ws1.Cells(10, "A"), 4)) <= 4130 Then

...in the relevant two lines of your procedure.
 
Upvote 0
Not sure I'm afraid. Hopefully someone on the forum will have a solution.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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