Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Formula depending on cell value

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Formula depending on cell value

Hi,

This assumes you are searching column A. Right click your sheet tab, view
code and paste this in and run it. You didn't say what formula so substitute
your own.

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If UCase(c.Value) = "TOTAL" Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub

Mike

"Enyaw" wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Formula depending on cell value

That worked Mike. Thanks. One more thing. What if total is only part of
the cell value. How do i search for that?

"Mike H" wrote:

Hi,

This assumes you are searching column A. Right click your sheet tab, view
code and paste this in and run it. You didn't say what formula so substitute
your own.

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If UCase(c.Value) = "TOTAL" Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub

Mike

"Enyaw" wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Formula depending on cell value

Hi,

use this

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "TOTAL") = 0 Then
sumrows = sumrows + 1
Else
c.Offset(, 1).Formula = "=sum(B" & c.Row - sumrows & ":B" & c.Row - 1 &
")"
sumrows = 0
End If
Next
End Sub

Mike

"Enyaw" wrote:

That worked Mike. Thanks. One more thing. What if total is only part of
the cell value. How do i search for that?

"Mike H" wrote:

Hi,

This assumes you are searching column A. Right click your sheet tab, view
code and paste this in and run it. You didn't say what formula so substitute
your own.

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If UCase(c.Value) = "TOTAL" Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub

Mike

"Enyaw" wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Formula depending on cell value

Hi,

Apologies I sent you a version I was playing with that inserted a formula
that summed column B up to the last time total appared in column A so ignore
and use this

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "TOTAL") 0 Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub


Mike




"Mike H" wrote:

Hi,

use this

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "TOTAL") = 0 Then
sumrows = sumrows + 1
Else
c.Offset(, 1).Formula = "=sum(B" & c.Row - sumrows & ":B" & c.Row - 1 &
")"
sumrows = 0
End If
Next
End Sub

Mike

"Enyaw" wrote:

That worked Mike. Thanks. One more thing. What if total is only part of
the cell value. How do i search for that?

"Mike H" wrote:

Hi,

This assumes you are searching column A. Right click your sheet tab, view
code and paste this in and run it. You didn't say what formula so substitute
your own.

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If UCase(c.Value) = "TOTAL" Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub

Mike

"Enyaw" wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Formula depending on cell value

Thanks Mike

"Mike H" wrote:

Hi,

Apologies I sent you a version I was playing with that inserted a formula
that summed column B up to the last time total appared in column A so ignore
and use this

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "TOTAL") 0 Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub


Mike




"Mike H" wrote:

Hi,

use this

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "TOTAL") = 0 Then
sumrows = sumrows + 1
Else
c.Offset(, 1).Formula = "=sum(B" & c.Row - sumrows & ":B" & c.Row - 1 &
")"
sumrows = 0
End If
Next
End Sub

Mike

"Enyaw" wrote:

That worked Mike. Thanks. One more thing. What if total is only part of
the cell value. How do i search for that?

"Mike H" wrote:

Hi,

This assumes you are searching column A. Right click your sheet tab, view
code and paste this in and run it. You didn't say what formula so substitute
your own.

Sub stantial()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If UCase(c.Value) = "TOTAL" Then
c.Offset(, 1).Formula = "=22/7"
End If
Next
End Sub

Mike

"Enyaw" wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Formula depending on cell value

One way:

Const csFIND As String = "*total*"
Const csFORM As String = "<your formula"
Dim rCell As Range

For Each rCell In <your dynamic range here
With rCell
If LCase(.Text) Like csFIND Then _
.Offset(0, 1).Formula = csFORM
End With
Next rCell


In article ,
Enyaw wrote:

How do I search through a dynamic range in one column and for each instance
the word total appears insert a formula into the cell next to it?

Thanks in advance

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
Formula in a cell depending on the value of another cell WVR Excel Discussion (Misc queries) 2 June 10th 09 09:14 PM
Formula to display text depending upon date entered in a cell Rod from B.C. Government Excel Worksheet Functions 2 May 25th 09 10:03 PM
Seperate formula depending on cell used duckydon Excel Discussion (Misc queries) 4 March 13th 09 12:53 PM
Value or formula in cell depending on input... Jan Jansens[_2_] Excel Programming 4 September 6th 05 08:54 PM


All times are GMT +1. The time now is 11:13 AM.

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"