Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DD DD is offline
external usenet poster
 
Posts: 68
Default Macro to copy A1:d1 if Column A has total spend

Hi,
Theres four columns of data A:D.
If Column A has "Total Spend ", copy header A1:D1 and paste it on the second
row below Total Spend. So for example,

A1 B1 C1 D1
Vendor Category Option Spend
ABC
IBM
MAC
Total Spend
(Blank Row)
Automatically Paste Vendor Category Option Spend
Sample Vendor1
Sample Vendor2
Sample Vendor3
Total Spend

Vendor Category Option Spend



Any help is appreciated. Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Macro to copy A1:d1 if Column A has total spend

select yr data and use the following macro:

Sub kopiuj()
For Each cell in Selection
If cell.Text = "Total Spend" Then
Range("A1:D1").Copy cell.Offset(2,0)
End If
Next cell
End Sub


I hope you don't store any data in any of the cells that 2 rows below
"Total Spend"
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Macro to copy A1:d1 if Column A has total spend

Should do the trick unless there's more to it. Hope it helps!

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value = "Total Spend" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub

"dd" wrote:

Hi,
Theres four columns of data A:D.
If Column A has "Total Spend ", copy header A1:D1 and paste it on the second
row below Total Spend. So for example,

A1 B1 C1 D1
Vendor Category Option Spend
ABC
IBM
MAC
Total Spend
(Blank Row)
Automatically Paste Vendor Category Option Spend
Sample Vendor1
Sample Vendor2
Sample Vendor3
Total Spend

Vendor Category Option Spend



Any help is appreciated. Thank you

  #4   Report Post  
Posted to microsoft.public.excel.programming
DD DD is offline
external usenet poster
 
Posts: 68
Default Macro to copy A1:d1 if Column A has total spend

Thanks StumpedAgain!
I have two more questions.

Is there a way to changed the "Total Spend" to Total Spend - anything?
Example, if the word was Total Spend - Apple or Total Spend - Cars?

Also is it possible to subtotal the column C for each cluster before the
header row? For example,

Vendor Category Option Spend
ABC Computer 50 1000
IBM Computer 3000
MAC Computer 9 2000
Total Spend - Computer 59 6000

Vendor Category Option Spend
1 Any 5 100
2 Any 0
3 Any 1 10
Total Spend - Any 6 110






"StumpedAgain" wrote:

Should do the trick unless there's more to it. Hope it helps!

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value = "Total Spend" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub

"dd" wrote:

Hi,
Theres four columns of data A:D.
If Column A has "Total Spend ", copy header A1:D1 and paste it on the second
row below Total Spend. So for example,

A1 B1 C1 D1
Vendor Category Option Spend
ABC
IBM
MAC
Total Spend
(Blank Row)
Automatically Paste Vendor Category Option Spend
Sample Vendor1
Sample Vendor2
Sample Vendor3
Total Spend

Vendor Category Option Spend



Any help is appreciated. Thank you

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Macro to copy A1:d1 if Column A has total spend

The following covers both questoins. (mind the wrapping) I had to use like
and a "*" for your first request. This program allows for different number
of rows in each section. Hope it helps! Let me know if there's anything
else.

-SA

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value Like "Total Spend*" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
ActiveCell.End(xlDown).Offset(0, 2) =
Application.Sum(Range(ActiveCell.Offset(1, 2),
ActiveCell.End(xlDown).Offset(-1, 2)))
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub

"dd" wrote:

Thanks StumpedAgain!
I have two more questions.

Is there a way to changed the "Total Spend" to Total Spend - anything?
Example, if the word was Total Spend - Apple or Total Spend - Cars?

Also is it possible to subtotal the column C for each cluster before the
header row? For example,

Vendor Category Option Spend
ABC Computer 50 1000
IBM Computer 3000
MAC Computer 9 2000
Total Spend - Computer 59 6000

Vendor Category Option Spend
1 Any 5 100
2 Any 0
3 Any 1 10
Total Spend - Any 6 110






"StumpedAgain" wrote:

Should do the trick unless there's more to it. Hope it helps!

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value = "Total Spend" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub

"dd" wrote:

Hi,
Theres four columns of data A:D.
If Column A has "Total Spend ", copy header A1:D1 and paste it on the second
row below Total Spend. So for example,

A1 B1 C1 D1
Vendor Category Option Spend
ABC
IBM
MAC
Total Spend
(Blank Row)
Automatically Paste Vendor Category Option Spend
Sample Vendor1
Sample Vendor2
Sample Vendor3
Total Spend

Vendor Category Option Spend



Any help is appreciated. Thank you



  #6   Report Post  
Posted to microsoft.public.excel.programming
DD DD is offline
external usenet poster
 
Posts: 68
Default Macro to copy A1:d1 if Column A has total spend

Thanks for the fast response. You solved my first question but I made a
mistake in asking my second question.
Under Column C, basically says Yes or the cell is blank and column D has the
spend amount. What I wanted to do was to subtotal the Spend amount in Column
D when there is Yes in Col C and the subtotal for the Column C would be
displayed under the total spend row in Column D. I appologize if this sounds
confusing. Thanks so much.

Vendor Category Option Spend
ABC Computer Yes 1000
IBM Computer 3000
MAC Computer Yes 2000
Total Spend - Computer 6000
3000
(so $3000 is displayed Col D)



"StumpedAgain" wrote:

The following covers both questoins. (mind the wrapping) I had to use like
and a "*" for your first request. This program allows for different number
of rows in each section. Hope it helps! Let me know if there's anything
else.

-SA

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value Like "Total Spend*" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
ActiveCell.End(xlDown).Offset(0, 2) =
Application.Sum(Range(ActiveCell.Offset(1, 2),
ActiveCell.End(xlDown).Offset(-1, 2)))
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Macro to copy A1:d1 if Column A has total spend

What is this a test? These questions keep evolving and getting more and more
involved! ;)

The following should do the trick. I had to change the exit point and
define some variables. Let me know if there's any more changes. (mind the
wrapping again)

-SA

Option Explicit
Sub Copy_Headers()

Dim i, m As Integer, r As Long

Range("A1").Select
r = 0

Do
If ActiveCell.Offset(1, 0) = "" Then Exit Do
With ActiveCell
m = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
End With
If ActiveCell.End(xlDown).Value Like "Total Spend*" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
ActiveCell.End(xlDown).Offset(0, 3) =
Application.Sum(Range(ActiveCell.Offset(1, 3),
ActiveCell.End(xlDown).Offset(-1, 3)))
For i = 0 To m
If ActiveCell.Offset(i, 2).Value Like "Yes" Then r = r +
ActiveCell.Offset(i, 3).Value
Next i
ActiveCell.End(xlDown).Offset(1, 3) = r
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub

"dd" wrote:

Thanks for the fast response. You solved my first question but I made a
mistake in asking my second question.
Under Column C, basically says Yes or the cell is blank and column D has the
spend amount. What I wanted to do was to subtotal the Spend amount in Column
D when there is Yes in Col C and the subtotal for the Column C would be
displayed under the total spend row in Column D. I appologize if this sounds
confusing. Thanks so much.

Vendor Category Option Spend
ABC Computer Yes 1000
IBM Computer 3000
MAC Computer Yes 2000
Total Spend - Computer 6000
3000
(so $3000 is displayed Col D)



"StumpedAgain" wrote:

The following covers both questoins. (mind the wrapping) I had to use like
and a "*" for your first request. This program allows for different number
of rows in each section. Hope it helps! Let me know if there's anything
else.

-SA

Option Explicit
Sub Copy_Headers()

Range("A1").Select

Do
If ActiveCell.End(xlDown).Value Like "Total Spend*" Then
Range("A1:D1").Copy ActiveCell.End(xlDown).Offset(2, 0)
ActiveCell.End(xlDown).Offset(0, 2) =
Application.Sum(Range(ActiveCell.Offset(1, 2),
ActiveCell.End(xlDown).Offset(-1, 2)))
Else: Exit Do
End If

ActiveCell.End(xlDown).Offset(2, 0).Select

Loop

End Sub


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
Finding top 20% of spend dollars in a column wjs81866 New Users to Excel 2 January 27th 09 06:26 AM
How can I calculate total spend on items that have different values [email protected] Excel Worksheet Functions 1 July 29th 08 04:01 PM
Copy Total to the following row in Column A dd Excel Programming 3 January 5th 07 10:27 AM
How do I estimate the year spend if spend is $26000 as of May? Felicia Pickett Excel Worksheet Functions 4 June 20th 06 04:08 AM
Column Total Needed via Macro LAT Excel Programming 0 January 21st 04 04:31 PM


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