View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default VBA help w/ look & fill in data

Did the code every work? You have a new problem now which is more
complicated and before we start changing code lets get the easier first
problem solved. Once I have the first problem solve the changes are pretty
easy to get the 2nd version working.

Why wasn't the original code working for you. Explain in detail!

"Cam" wrote:

Joel,

The code is not working for me. It just filled out blank data in sheet1.
I thought maybe to make it simplier by seperating the two models into
individual sheet.

So, sheet3 will still be the raw data, but now sheet1 is for 100 model and
sheet2 for 200 model. look something like below. All the code have to do is
to look at the raw data in sheet3, sort by model number and operation. Then,
for all the data for model 100 in sheet1, fill in the S/O starting column D:J
with the S/O that have the highest operation go first. Same for model 200. I
forgot to mention that the Ref column in raw data sheet has difference number
for model 100 & 200. See sample below.

sheet1
No. ShipDate Model 1301 1301 1501 1501 Operation
1001 17-Aug 100
1004 19-Aug 100 vendor vendor vendor vendor N/A N/A N/A N/A
1007 25-Aug 100
1008 25-Aug 100

sheet2
No. ShipDate Model 1302 1302 1502 1502 Operation
1002 18-Aug 200
1003 19-Aug 200
1006 21-Aug 200

Sorry, for all the confusion.


"Joel" wrote:

Change one line of code to clear cell C to Z (make wnhat ever you need)

From: clear entire row
Rows(cell.Row).ClearContents

To: clear cells C to Z
.Range("C" & cell.Row & ":Z" & _
cell.Row).ClearContents

"Cam" wrote:

Thank you Joel.

Can I not clear column A & B on sheet1? They will be template and
information is fixed (all filled out up to No. 1100, etc).

"Joel" wrote:

I ws expecting that you would agree with me. Have been working the code
before you asked for it. The code will clear sheet 1 and skip and rows with
vendor in column D. I also cleared column A and B because I don't know what
should be in these columns. the code has 3 subroutines to make the code
common for all models and Ref values. Run checkso()


Const OP = 0
Const SO = 1
Const Ref1300 = 0
Const Ref1500 = 2

Sub checkso()

Dim R1300M100(1000, 2)
Dim R1300M200(1000, 2)
Dim R1500M100(1000, 2)
Dim R1500M200(1000, 2)

With Sheets("Sheet1")
LastRowSh1 = _
.Cells(Rows.Count, "C").End(xlUp).Row
Set ColDRange = .Range(.Cells(2, "D"), _
.Cells(LastRowSh1, "D"))
For Each cell In ColDRange
If cell < "vendor" Then
Rows(cell.Row).ClearContents
End If
Next cell
End With

LastRowSh2 = Sheets("Sheet2"). _
Cells(Rows.Count, "A").End(xlUp).Row

R1300M100Count = 0
R1300M200Count = 0
R1500M100Count = 0
R1500M200Count = 0

With Sheets("Sheet2")

For Sh2RowCount = 2 To LastRowSh2

OPeration = .Cells(Sh2RowCount, "B")
ShippingOrder = .Cells(Sh2RowCount, "A")
Model = .Cells(Sh2RowCount, "D")
If .Cells(Sh2RowCount, "C").Value = 1300 Then

If .Cells(Sh2RowCount, "D").Value = 100 Then

R1300M100Count = R1300M100Count + 1
R1300M100(R1300M100Count, OP) = _
OPeration
R1300M100(R1300M100Count, SO) = _
ShippingOrder
End If
If .Cells(Sh2RowCount, "D").Value = 200 Then

R1300M200Count = R1300M200Count + 1
R1300M200(R1300M200Count, OP) = _
OPeration
R1300M200(R1300M200Count, SO) = _
ShippingOrder
End If

End If
If .Cells(Sh2RowCount, "C").Value = 1500 Then

If .Cells(Sh2RowCount, "D").Value = 100 Then

R1500M100Count = R1500M100Count + 1
R1500M100(R1500M100Count, OP) = _
OPeration
R1500M100(R1500M100Count, SO) = _
ShippingOrder
End If
If .Cells(Sh2RowCount, "D").Value = 200 Then

R1500M200Count = R1500M200Count + 1
R1500M200(R1500M200Count, OP) = _
OPeration
R1500M200(R1500M200Count, SO) = _
ShippingOrder
End If
End If
Next Sh2RowCount
End With
Call SortData(R1300M100, R1300M100Count)
Call SortData(R1300M200, R1300M200Count)
Call SortData(R1500M100, R1500M100Count)
Call SortData(R1500M200, R1500M200Count)

Call InsertData(R1300M100, R1300M100Count, _
Ref1300, 100)
Call InsertData(R1300M200, R1300M200Count, _
Ref1300, 200)
Call InsertData(R1500M100, R1500M100Count, _
Ref1500, 100)
Call InsertData(R1500M200, R1500M200Count, _
Ref1500, 200)

End Sub

Sub SortData(ByRef MyArray() As Variant, Count)

For i = 0 To (Count - 2)
For j = (i + 1) To (Count - 1)
If MyArray(j, OP) MyArray(i, OP) Then
Temp = MyArray(i, OP)
MyArray(i, OP) = MyArray(j, OP)
MyArray(j, OP) = Temp

Temp = MyArray(i, SO)
MyArray(i, SO) = MyArray(j, SO)
MyArray(j, SO) = Temp
End If
Next j
Next i
End Sub
Sub InsertData(ByRef MyArray() As Variant, _
Count, Ref, Model)

With Sheets("Sheet1")
RowCount = 2
MyOffset = 0
Do While (.Cells(RowCount, "D"). _
Offset(0, Ref) < "") And _
((.Cells(RowCount, "C") < Model) Or _
(.Cells(RowCount, "D") = "vendor"))

RowCount = RowCount + 1
Loop
For LoopCount = 0 To (Count - 1)
.Cells(RowCount, "D"). _
Offset(0, Ref + MyOffset) = _
MyArray(LoopCount, SO)
.Cells(RowCount, "H"). _
Offset(0, Ref + MyOffset) = _
MyArray(LoopCount, OP)

If MyOffset = 0 Then
.Cells(RowCount, "C").Value = Model
MyOffset = 1
Else
RowCount = RowCount + 1
Do While (.Cells(RowCount, "D"). _
Offset(0, Ref) < "") And _
((.Cells(RowCount, "C") < Model) Or _
(.Cells(RowCount, "D") = "vendor"))

RowCount = RowCount + 1
Loop
MyOffset = 0
End If
Next LoopCount
End With
End Sub


"Cam" wrote:

Joel,

Thank you for leading me to some thought. I think you are right that all I
wanted was to take the raw data in sheet2 pulled from our system then place
S/O in sheet2 based on the model and highest operation number going first.

So, what I need to include in the code is the refresh (delete) all existing
data in sheet1 first. Also, what I need to do manually is also, hide row with
the No. (etc.. 1001) that are already completed so it will always start
filling in from the first row and down. And I am not sure if the code also
need to say not to fill in the data with the rows hidden.

"Joel" wrote:

Cam: It looks like you want my 1st solution, not the second solution! The
problem is there are multiple rows on Sheet 1 with the same model number. I
don't know which items one sheet 2 go on which rows on sheet 1.

I don't know how important column A (No) and B (Date) are in sheet1, but
ithere is no way it can be correlated to the data in sheet2. I think what
you really want is to take the data in sheet 2 and place it in sheet 1 with
highest operation number going first.

Think about what I wrote above and let me know how to proceeed.

"Cam" wrote:

Joel,

Thanks for your patience and help. The code is almost what I wanted.
When I run your data, it seemed like it look for data in sheet2 and add to
existence data in sheet1. I would like to update all the data in sheet1 by
using all data in sheet2.

Example:
Before running the macro, my data will have No., ShipDate & Model filled out
up to 50 rows. Then column D:K could be blank. Once the macro is ran, it will
fill in all the data starting from row 2 (No. 1001). Also, not fill in row 5
(No. 1004).
The S/O on sheet 2 will not shown up once all the operations are completed
and closed out. So if No. 1001 has all the S/O (not in sheet2 anymore) that
are completed I will hide 1001 row.
The same process repeat again.

No. ShipDate Model 1300 1300 1500 1500 Operation Status
1001 17-Aug 100
1002 18-Aug 200
1003 19-Aug 200
1004 19-Aug 100 vendor vendor vendor vendor N/A N/A N/A N/A
1006 21-Aug 200
1007 25-Aug 100
1008 25-Aug 100



"Joel" wrote:

You are going to have to fix the problems with your worksheet. Apparently
you have spaces the cells that contain numbers. Make sure all the numbers
are right justified in the cell (left justified indicates they are text).
You can easily get rid of the spaces by using the Spreadsheet Replace (under
edit menu). Highligh the cells containing number. the replace a single
space with nothing. Just enter a space in the from box and leave the replace
box empty.

The code becomes very complex to handle numbers and text mixed. fix both
sheet 1 and 2.

Below is the code I think you want. I put in the Operation number and well
as the SO number.


Sub checkso()

Const High2 = 0
Const High1 = 1
Const OP = 0
Const SO = 1
Dim R1300M100(2, 2)
Dim R1300M200(2, 2)
Dim R1500M100(2, 2)
Dim R1500M200(2, 2)

R1300M100(High1, OP) = 0
R1300M100(High2, OP) = 0
R1300M100(High1, SO) = 0
R1300M100(High2, SO) = 0
R1300M200(High1, OP) = 0
R1300M200(High2, OP) = 0