Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default stuck please help

i posted this before but i think it was way comfusing.
i have a spreadsheet we download once a week. i have code written to d
what i want so far. it basically subtracts how many parts we owe dif
companies from what we have on hand. i have it to subtract until i
hits a negative number , then highlight the last date we ca
ship.(written by pikus) what i have been trying to do, and failing a
it since then, is have the remainder left over to show in the firs
emtpy cell at the end of the row, and highlight it.

ex:

the on hand number starts in g4, then it goes down the row subtractin
until it hits a neg number. then the last positive number used needs t
be placed at the first empty cell at the end of that row. the
highlighted.

if anything of this is possible i appreciate it, here is the code as i
is now.

Private Sub launchbutton_1_Click()

lastRow = Worksheets("First Sheet").UsedRange.Row - 1
Worksheets("First Sheet").UsedRange.Rows.Count
lastCol = Worksheets("First Sheet").UsedRange.Column - 1
Worksheets("First Sheet").UsedRange.Columns.Count

With Worksheets("First Sheet")
For x = 2 To lastRow
On Error GoTo Skip
y = 7
runTot = 0
parts = .Cells(x, 7).Value
Do Until y = lastCol _
Or runTot parts
y = y + 1
runTot = runTot + .Cells(x, y).Value
Loop
If runTot parts Then
For z = 8 To y - 1
.Cells(x, z).Interior.ColorIndex = 6
Next z
ElseIf y = lastCol Then
For z = 8 To y
If .Cells(x, z).Value < "" Then
.Cells(x, z).Interior.ColorIndex = 6
End If
Next z
End If
Skip:
Next x

End With
End Sub


thank

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default stuck please help

The following was my interpretation. My interpretation
of "remainder" may be in error but should be easily
fixed. If rewrote the code according to my own style.
Hope it's what you want.

Private Sub launchbutton_1_Click()
Dim LastRow As Long, LastCol As Integer
Dim X As Long, Y As Integer
Dim RunTot As Single, Parts As Single
Dim Remainder As Single, EmptyCell As Range
With Worksheets("First Sheet")
With .UsedRange
LastRow = .Row - 1 + .Rows.Count
LastCol = .Column - 1 + .Columns.Count
End With

For X = 2 To LastRow
On Error GoTo Skip
Y = 7
RunTot = 0
Parts = .Cells(X, 7).Value
Set EmptyCell = .Cells(X, LastCol + 1)
Do Until Y = LastCol Or RunTot Parts
Y = Y + 1
RunTot = RunTot + .Cells(X, Y).Value
If RunTot <= Parts Then
If .Cells(X, Y) < "" Then
.Cells(X, Y).Interior.ColorIndex = 6
Remainder = Parts - RunTot
Else
Set EmptyCell = .Cells(X, Y)
Exit Do
End If
End If
Loop
If Remainder < 0 Then _
Remainder = Remainder + .Cells(X, Y)
EmptyCell.Value = Remainder
EmptyCell.Interior.ColorIndex = 3
Skip:
Next X
End With

End Sub

Not rigorously tested. That's your job.

Regards,
Greg
(VBA amateur)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default stuck please help

I forgot to remove the following lines. They are
unnecessary:

If Remainder < 0 Then _
Remainder = Remainder + .Cells(X, Y)

Regards,
Greg

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Im stuck again... Meader Excel Discussion (Misc queries) 2 May 29th 07 01:23 AM
Help, please, I'm stuck Harvest Excel Discussion (Misc queries) 3 August 19th 06 03:28 AM
Stuck... Mike Excel Discussion (Misc queries) 4 May 22nd 06 08:09 PM
Stuck with an =IF Mark R... Excel Worksheet Functions 2 January 25th 06 04:41 PM
Still Stuck Josh in Tampa Excel Programming 9 October 28th 03 05:15 AM


All times are GMT +1. The time now is 02:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"