Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
DMB
 
Posts: n/a
Default How do I add the E column basd on the F column

The following code steps through all the worksheets and all the cells in the
range f2 thru f40, If the value in Fx = projectname I want to add the values
in the cell to the left, Ex. Using the for each statement is nice but how do
I get the info from Ex if Fx = projectname. I have tried to make E a variable
based on Cel, a collection object, but I keep getting errrors.

This is the line that is crashing:
TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) + CDbl(Range("cel.Column
- 1" & "cel.Row")) ' does not work - ie. F20 & E20

It would look like this:
if projectname = bell then
Total = Total + E20
end if

This is the part of that line that I need to work but doesn't:
CDbl(Range("cel.Column - 1" & "cel.Row")) ' ie. F20 & E20



'MsgBox (1)
Dim sht As Worksheet
Dim cel As Range
Dim j, column As Integer
For Each sht In Worksheets
For Each cel In sht.Range("F2:F40")
column = E
MsgBox (Cells("column & cel.Row"))
If cel.Text = TotalHours.Projects.Text Then
TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) +
CDbl(Range("cel.Column - 1" & "cel.Row")) ' does not work
'TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) +
CDbl(TotalHoursToDate.Text) ' works

End If
'MsgBox (cel.Row)
Next cel
Next sht


Thank you for the help. I have searched thru meny articles but I cant apply
their suggestion of the for each in this case!
  #2   Report Post  
Posted to microsoft.public.excel.misc
bpeltzer
 
Posts: n/a
Default How do I add the E column basd on the F column

CDbl(Range("cel.Column - 1" & "cel.Row"))...
Enclosing the cel.row and cel.column in quotes will prevent Excel from
evaluating the expressions. It's not clear to me whether cel.Column is
numeric or alpha. If numeric, I think you'll need
CDbl(cells(cel.Row,cel.Column-1)). If alpha, then I think you can just drop
the quotes.

"DMB" wrote:

The following code steps through all the worksheets and all the cells in the
range f2 thru f40, If the value in Fx = projectname I want to add the values
in the cell to the left, Ex. Using the for each statement is nice but how do
I get the info from Ex if Fx = projectname. I have tried to make E a variable
based on Cel, a collection object, but I keep getting errrors.

This is the line that is crashing:
TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) + CDbl(Range("cel.Column
- 1" & "cel.Row")) ' does not work - ie. F20 & E20

It would look like this:
if projectname = bell then
Total = Total + E20
end if

This is the part of that line that I need to work but doesn't:
CDbl(Range("cel.Column - 1" & "cel.Row")) ' ie. F20 & E20



'MsgBox (1)
Dim sht As Worksheet
Dim cel As Range
Dim j, column As Integer
For Each sht In Worksheets
For Each cel In sht.Range("F2:F40")
column = E
MsgBox (Cells("column & cel.Row"))
If cel.Text = TotalHours.Projects.Text Then
TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) +
CDbl(Range("cel.Column - 1" & "cel.Row")) ' does not work
'TotalHoursToDate.Text = CDbl(TotalHoursToDate.Text) +
CDbl(TotalHoursToDate.Text) ' works

End If
'MsgBox (cel.Row)
Next cel
Next sht


Thank you for the help. I have searched thru meny articles but I cant apply
their suggestion of the for each in this case!

  #3   Report Post  
Posted to microsoft.public.excel.misc
DMB
 
Posts: n/a
Default How do I add the E column basd on the F column

Thanks for the quick reply! I will try this and write back tomarrow if I have
made that work. I have been trying for hours to do this one thing!
  #4   Report Post  
Posted to microsoft.public.excel.misc
DMB
 
Posts: n/a
Default How do I add the E column basd on the F column

Hey I just tried it and I am getting an

error 1004
Method 'Range' of Object '_Global' failed.

This is the error that I keep getting with the range object


  #5   Report Post  
Posted to microsoft.public.excel.misc
bpeltzer
 
Posts: n/a
Default How do I add the E column basd on the F column

Which 'it' did you try? What's the value of cel.column. As noted, if it's a
number, use Cells rather than Range; ex: CDbl(cells(cel.Row,cel.Column-1)).

"DMB" wrote:

Hey I just tried it and I am getting an

error 1004
Method 'Range' of Object '_Global' failed.

This is the error that I keep getting with the range object


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
Check COlumn - Excel VBA magix Excel Discussion (Misc queries) 11 November 5th 05 02:32 AM
creating a bar graph Johnfli Excel Discussion (Misc queries) 0 October 26th 05 08:16 PM
Count Position of Filtered TEXT cells in a column Sam via OfficeKB.com Excel Worksheet Functions 8 May 18th 05 04:23 AM
How to group similar column titles together???? vrk1 Excel Discussion (Misc queries) 2 April 30th 05 12:17 AM
Return Count for LAST NonBlank Cell in each Row Sam via OfficeKB.com Excel Worksheet Functions 12 April 17th 05 10:36 PM


All times are GMT +1. The time now is 11:14 PM.

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

About Us

"It's about Microsoft Excel"