Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Need code for fill a number trend down

I need to write a macro to fill Column C based on Column B. Column A has all
rows filled with text. Code needs to start reading at B2 (Row 1 contains my
headers) and enter a number trend down in Column C until it reads the next
number in Column B, then start the trend again and continue until the last
line of Column A. Column B is already filled out. I just need code to fill
Column C. Is this possible? I don't know where to begin with the code.
Your help would be greatly appreciated. I am using Excel 2002.
My spreadsheet example below.
Column B Column C
1 1
2
3
2 1
2
3 1
2
3
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Need code for fill a number trend down

Hi Sheryl,

Hope this code answers your question. If not right then get back to me
because I am not 100% sure that I have correctly interpreted your question.
Code is based on the active worksheet.


Sub Number_Trend()

Dim rngC As Range
Dim cel As Range
Dim lngLastRow As Long
Dim lngCounter As Long

'find number of last row in column A
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'set range in column C from 2nd row to row matching
'last row in column A
Set rngC = Range(Cells(2, "C"), Cells(lngLastRow, "C"))

'Loop through cells in column C and set values
'based on data/no data in column B
For Each cel In rngC
If cel.Offset(0, -1).Value 0 Then
lngCounter = 1
Else
lngCounter = lngCounter + 1
End If
cel.Value = lngCounter
Next cel

End Sub

--
Regards,

OssieMac


"Sheryl" wrote:

I need to write a macro to fill Column C based on Column B. Column A has all
rows filled with text. Code needs to start reading at B2 (Row 1 contains my
headers) and enter a number trend down in Column C until it reads the next
number in Column B, then start the trend again and continue until the last
line of Column A. Column B is already filled out. I just need code to fill
Column C. Is this possible? I don't know where to begin with the code.
Your help would be greatly appreciated. I am using Excel 2002.
My spreadsheet example below.
Column B Column C
1 1
2
3
2 1
2
3 1
2
3

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Need code for fill a number trend down

Thank you so much. You interpreted it 100%. Since you are so awesome at
this, could you tell me what the code would be to take Column B, start at the
1 and fill that down with 1 until 2, then fill 2 down with 2 until 3 and so
on? Also, thanks for responding so quick too, especially on a Friday.

"OssieMac" wrote:

Hi Sheryl,

Hope this code answers your question. If not right then get back to me
because I am not 100% sure that I have correctly interpreted your question.
Code is based on the active worksheet.


Sub Number_Trend()

Dim rngC As Range
Dim cel As Range
Dim lngLastRow As Long
Dim lngCounter As Long

'find number of last row in column A
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'set range in column C from 2nd row to row matching
'last row in column A
Set rngC = Range(Cells(2, "C"), Cells(lngLastRow, "C"))

'Loop through cells in column C and set values
'based on data/no data in column B
For Each cel In rngC
If cel.Offset(0, -1).Value 0 Then
lngCounter = 1
Else
lngCounter = lngCounter + 1
End If
cel.Value = lngCounter
Next cel

End Sub

--
Regards,

OssieMac


"Sheryl" wrote:

I need to write a macro to fill Column C based on Column B. Column A has all
rows filled with text. Code needs to start reading at B2 (Row 1 contains my
headers) and enter a number trend down in Column C until it reads the next
number in Column B, then start the trend again and continue until the last
line of Column A. Column B is already filled out. I just need code to fill
Column C. Is this possible? I don't know where to begin with the code.
Your help would be greatly appreciated. I am using Excel 2002.
My spreadsheet example below.
Column B Column C
1 1
2
3
2 1
2
3 1
2
3

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Need code for fill a number trend down

Hi again Sheryl,

I am not sure whether you want to increment the numbers in column C from 1
to whatever or whether you mean that you want them to match the numbers in
column B so I have provided both macros. The first increments from 1 and the
second matches the number found in column B. Of course if the numbers in
column B increment from 1 then it will not matter which one you use.

Sub Number_Trend_2()

Dim rngC As Range
Dim cel As Range
Dim lngLastRow As Long
Dim lngCounter As Long

'find number of last row in column A
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'set range in column C from 2nd row to row matching
'last row in column A
Set rngC = Range(Cells(2, "C"), Cells(lngLastRow, "C"))

'Loop through cells in column C and increment value
'in column C each time a value is found in column B
For Each cel In rngC
If cel.Offset(0, -1).Value 0 Then
lngCounter = lngCounter + 1
End If
cel.Value = lngCounter
Next cel

End Sub



Sub Number_Trend_3()

Dim rngC As Range
Dim cel As Range
Dim lngLastRow As Long
Dim lngCounter As Long

'find number of last row in column A
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'set range in column C from 2nd row to row matching
'last row in column A
Set rngC = Range(Cells(2, "C"), Cells(lngLastRow, "C"))

'Loop through cells in column C and set values
'in column C based on value in column B
For Each cel In rngC
If cel.Offset(0, -1).Value 0 Then
lngCounter = cel.Offset(0, -1).Value
End If
cel.Value = lngCounter
Next cel

End Sub


--
Regards,

OssieMac


"Sheryl" wrote:

Thank you so much. You interpreted it 100%. Since you are so awesome at
this, could you tell me what the code would be to take Column B, start at the
1 and fill that down with 1 until 2, then fill 2 down with 2 until 3 and so
on? Also, thanks for responding so quick too, especially on a Friday.

"OssieMac" wrote:

Hi Sheryl,

Hope this code answers your question. If not right then get back to me
because I am not 100% sure that I have correctly interpreted your question.
Code is based on the active worksheet.


Sub Number_Trend()

Dim rngC As Range
Dim cel As Range
Dim lngLastRow As Long
Dim lngCounter As Long

'find number of last row in column A
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

'set range in column C from 2nd row to row matching
'last row in column A
Set rngC = Range(Cells(2, "C"), Cells(lngLastRow, "C"))

'Loop through cells in column C and set values
'based on data/no data in column B
For Each cel In rngC
If cel.Offset(0, -1).Value 0 Then
lngCounter = 1
Else
lngCounter = lngCounter + 1
End If
cel.Value = lngCounter
Next cel

End Sub

--
Regards,

OssieMac


"Sheryl" wrote:

I need to write a macro to fill Column C based on Column B. Column A has all
rows filled with text. Code needs to start reading at B2 (Row 1 contains my
headers) and enter a number trend down in Column C until it reads the next
number in Column B, then start the trend again and continue until the last
line of Column A. Column B is already filled out. I just need code to fill
Column C. Is this possible? I don't know where to begin with the code.
Your help would be greatly appreciated. I am using Excel 2002.
My spreadsheet example below.
Column B Column C
1 1
2
3
2 1
2
3 1
2
3

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
How to fill or shade space between to trend lines? Thorsten Charts and Charting in Excel 4 April 28th 23 07:42 PM
Fill Cells with same number in three rows then skip to next number Tracy Excel Worksheet Functions 2 November 7th 08 03:12 PM
Auto Fill (number & its repeat in bar code) for stickers Sonny Dumas Excel Programming 0 May 12th 06 06:20 AM
Trend using the same formula as the fill handle does Roy G. Biv Excel Worksheet Functions 0 October 18th 05 08:31 PM
Can I auto fill a cell in one worksheet by typing a code number Gomer Pyle Excel Worksheet Functions 1 August 27th 05 01:24 AM


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