Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default pulling values from column g into a variable, and returning variableon spreadsheet

Im running into some issues and I have an idea as to what the problem
is but I have no idea how to solve it. The following code will
highlight any rows that have a column F value = RollVal. I tried to
modify it to also add up all the values of column G if the value of
column F and return this value in cell J2, but my coding skills seem
to be severely lacking. I think the problem is that it is trying to
include the values of the header row, which is obviously not currency
or any numerical value at all. Would making the objRow start with Row
2 fix this? Here is the code:

Sub RollCalc()


Dim RollVal As Long
Dim objRow As Object
Dim TotalRoll As Currency
Dim Bal As Currency


RollVal = Application.InputBox("What is the Roll DPD?", _
"Get Roll DPD Value ", Type:=1)


For Each objRow In ActiveSheet.UsedRange.Rows
If Cells(objRow.Row, "F").Value = RollVal Then
objRow.Interior.ColorIndex = 45
Bal = Cells(objRow.Row, "G").Value
TotalRoll = TotalRoll + Bal
Else
objRow.Interior.ColorIndex = xlNone

End If
Next objRow

Range("J2").FormulaR1C1 = TotalRoll


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default pulling values from column g into a variable, and returning variable on spreadsheet

Sub hiliteif()
Rows.Interior.ColorIndex = 0
rollval = Application.InputBox("What is the Roll DPD?", _
"Get Roll DPD Value ", Type:=1)

For i = 2 To Cells(Rows.Count, "f").End(xlUp).Row
If Cells(i, "f") rollval Then
Rows(i).Interior.ColorIndex = 45
ms = ms + Cells(i, "g")
End If
Next i
Range("J2").Value = ms
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Matthew Dyer" wrote in message
...
Im running into some issues and I have an idea as to what the problem
is but I have no idea how to solve it. The following code will
highlight any rows that have a column F value = RollVal. I tried to
modify it to also add up all the values of column G if the value of
column F and return this value in cell J2, but my coding skills seem
to be severely lacking. I think the problem is that it is trying to
include the values of the header row, which is obviously not currency
or any numerical value at all. Would making the objRow start with Row
2 fix this? Here is the code:

Sub RollCalc()


Dim RollVal As Long
Dim objRow As Object
Dim TotalRoll As Currency
Dim Bal As Currency


RollVal = Application.InputBox("What is the Roll DPD?", _
"Get Roll DPD Value ", Type:=1)


For Each objRow In ActiveSheet.UsedRange.Rows
If Cells(objRow.Row, "F").Value = RollVal Then
objRow.Interior.ColorIndex = 45
Bal = Cells(objRow.Row, "G").Value
TotalRoll = TotalRoll + Bal
Else
objRow.Interior.ColorIndex = xlNone

End If
Next objRow

Range("J2").FormulaR1C1 = TotalRoll


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default pulling values from column g into a variable, and returningvariable on spreadsheet

On Oct 6, 12:09*pm, "Don Guillett" wrote:
Sub hiliteif()
Rows.Interior.ColorIndex = 0
rollval = Application.InputBox("What is the Roll DPD?", _
* * "Get Roll DPD Value ", Type:=1)

For i = 2 To Cells(Rows.Count, "f").End(xlUp).Row
If Cells(i, "f") rollval Then
Rows(i).Interior.ColorIndex = 45
ms = ms + Cells(i, "g")
End If
Next i
Range("J2").Value = ms
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Matthew Dyer" wrote in message

...



Im running into some issues and I have an idea as to what the problem
is but I have no idea how to solve it. The following code will
highlight any rows that have a column F value = RollVal. I tried to
modify it to also add up all the values of column G if the value of
column F and return this value in cell J2, but my coding skills seem
to be severely lacking. I think the problem is that it is trying to
include the values of the header row, which is obviously not currency
or any numerical value at all. Would making the objRow start with Row
2 fix this? Here is the code:


Sub RollCalc()


Dim RollVal As Long
Dim objRow As Object
Dim TotalRoll As Currency
Dim Bal *As Currency


RollVal = Application.InputBox("What is the Roll DPD?", _
* *"Get Roll DPD Value ", Type:=1)


For Each objRow In ActiveSheet.UsedRange.Rows
* *If Cells(objRow.Row, "F").Value = RollVal Then
* * * *objRow.Interior.ColorIndex = 45
* * * *Bal = Cells(objRow.Row, "G").Value
* * * *TotalRoll = TotalRoll + Bal
* *Else
* * * *objRow.Interior.ColorIndex = xlNone


* *End If
Next objRow


Range("J2").FormulaR1C1 = TotalRoll


End Sub- Hide quoted text -


- Show quoted text -


This works fantastic! One request though... I really liked the
origional code is that it would only highlight the used range of
cells. Using this code, how do I stop highlighting at the end of my
range of columns? If it helps my range ends at column H. I tried the
following change, but it didnt work:

If Cells(i, "f") = RollVal Then
Rows(i, "H").Interior.ColorIndex = 45

I get an error saying "Application-defined or object-defined error

The best I could do for now is to just highlight one specific column
with the following code:

If Cells(i, "f") = RollVal Then
Cells(i, "F").Interior.ColorIndex = 45

I also tried to do Cells(i, "A:H").Interior... but that didnt work
either.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default pulling values from column g into a variable, and returning variable on spreadsheet

When replying to me please TOP post so I don't have to look for your reply.

Cells(i, 1).Resize(, 8).Interior.ColorIndex = 45

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Matthew Dyer" wrote in message
...
On Oct 6, 12:09 pm, "Don Guillett" wrote:
Sub hiliteif()
Rows.Interior.ColorIndex = 0
rollval = Application.InputBox("What is the Roll DPD?", _
"Get Roll DPD Value ", Type:=1)

For i = 2 To Cells(Rows.Count, "f").End(xlUp).Row
If Cells(i, "f") rollval Then
Rows(i).Interior.ColorIndex = 45
ms = ms + Cells(i, "g")
End If
Next i
Range("J2").Value = ms
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Matthew Dyer" wrote in
message

...



Im running into some issues and I have an idea as to what the problem
is but I have no idea how to solve it. The following code will
highlight any rows that have a column F value = RollVal. I tried to
modify it to also add up all the values of column G if the value of
column F and return this value in cell J2, but my coding skills seem
to be severely lacking. I think the problem is that it is trying to
include the values of the header row, which is obviously not currency
or any numerical value at all. Would making the objRow start with Row
2 fix this? Here is the code:


Sub RollCalc()


Dim RollVal As Long
Dim objRow As Object
Dim TotalRoll As Currency
Dim Bal As Currency


RollVal = Application.InputBox("What is the Roll DPD?", _
"Get Roll DPD Value ", Type:=1)


For Each objRow In ActiveSheet.UsedRange.Rows
If Cells(objRow.Row, "F").Value = RollVal Then
objRow.Interior.ColorIndex = 45
Bal = Cells(objRow.Row, "G").Value
TotalRoll = TotalRoll + Bal
Else
objRow.Interior.ColorIndex = xlNone


End If
Next objRow


Range("J2").FormulaR1C1 = TotalRoll


End Sub- Hide quoted text -


- Show quoted text -


This works fantastic! One request though... I really liked the
origional code is that it would only highlight the used range of
cells. Using this code, how do I stop highlighting at the end of my
range of columns? If it helps my range ends at column H. I tried the
following change, but it didnt work:

If Cells(i, "f") = RollVal Then
Rows(i, "H").Interior.ColorIndex = 45

I get an error saying "Application-defined or object-defined error

The best I could do for now is to just highlight one specific column
with the following code:

If Cells(i, "f") = RollVal Then
Cells(i, "F").Interior.ColorIndex = 45

I also tried to do Cells(i, "A:H").Interior... but that didnt work
either.

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
Returning multiple values that are NOT in a single column or row crispino Excel Worksheet Functions 8 April 24th 09 02:45 AM
column returning null values jjordan Excel Programming 0 October 23rd 07 06:51 PM
Looking up data in a column, then returning values of respective row TC Excel Discussion (Misc queries) 4 March 22nd 06 02:47 PM
Formula for Returning values in another spreadsheet lrbest4x4xfar Excel Worksheet Functions 1 October 14th 05 02:52 PM
returning values multi column listbox GeorgeFD29 Excel Programming 4 May 17th 05 01:23 PM


All times are GMT +1. The time now is 03:33 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"