Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy down command button

I have a command button placed at the end of the first 40 rows o
Sheet1. When pushed, the button inserts an equation into about
different cells on that particular row, copies the cells, and paste
the values only.

In the next row down, the same equations are pasted, copied and value
pasted.


Is it possible to copy-down the VB Code so that I do not have to kee
duplicating and changing it all the way down to row 500. The onl
updates in the macro are subtracting 1 from [R] in each of th
equations. Each row that I move down and put a command button,
subtract 1 from the [R] value.


Sub CalculateRow12()

Range("K12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[-5]C[-9]"
Range("N12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[15]C[-6]"
Range("O12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[3]C[-7]"
Range("P12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[5]C[-8]"
Range("Q12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[2]C[-9]"
Range("W12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[29]C[-15]"
Range("X12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[31]C[-16]"
Range("Z12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[30]C[-18]"
Range("AA12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[32]C[-19]"
Range("K12:R12").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone
SkipBlanks:= _
False, Transpose:=False
Range("V12:Z12").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("K12").Select
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Copy down command button

If the formulas are the same, simply incrementing the row by one, you could
use a sub like the one below, to do all 489 rows at once.
You can also make the row or column reference absolute, by changing from
R[?] to RX, where X is the row number, for example.

HTH,
Bernie
MS Excel MVP

Sub CalculateRow12To500()

Range("K12").Resize(489, 1).FormulaR1C1 = "=R[-5]C[-9]"
Range("N12").Resize(489, 1).FormulaR1C1 = "=R[15]C[-6]"
Range("O12").Resize(489, 1).FormulaR1C1 = "=R[3]C[-7]"
Range("P12").Resize(489, 1).FormulaR1C1 = "=R[5]C[-8]"
Range("Q12").Resize(489, 1).FormulaR1C1 = "=R[2]C[-9]"
Range("W12").Resize(489, 1).FormulaR1C1 = "=R[29]C[-15]"
Range("X12").Resize(489, 1).FormulaR1C1 = "=R[31]C[-16]"
Range("Z12").Resize(489, 1).FormulaR1C1 = "=R[30]C[-18]"
Range("AA12").Resize(489, 1).FormulaR1C1 = "=R[32]C[-19]"
Range("K12:R12").Resize(489, 8).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Range("V12:Z12").Resize(489, 5).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Range("K12").Select
End Sub

"sowetoddid " wrote in message
...
I have a command button placed at the end of the first 40 rows of
Sheet1. When pushed, the button inserts an equation into about 8
different cells on that particular row, copies the cells, and pastes
the values only.

In the next row down, the same equations are pasted, copied and values
pasted.


Is it possible to copy-down the VB Code so that I do not have to keep
duplicating and changing it all the way down to row 500. The only
updates in the macro are subtracting 1 from [R] in each of the
equations. Each row that I move down and put a command button, I
subtract 1 from the [R] value.


Sub CalculateRow12()

Range("K12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[-5]C[-9]"
Range("N12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[15]C[-6]"
Range("O12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[3]C[-7]"
Range("P12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[5]C[-8]"
Range("Q12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[2]C[-9]"
Range("W12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[29]C[-15]"
Range("X12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[31]C[-16]"
Range("Z12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[30]C[-18]"
Range("AA12").Select
ActiveCell.FormulaR1C1 = "=PollutantSummaries!R[32]C[-19]"
Range("K12:R12").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("V12:Z12").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("K12").Select
End Sub


---
Message posted from http://www.ExcelForum.com/



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
copy cell by command button kalpesh Excel Worksheet Functions 1 December 28th 11 08:41 PM
copy the command button and macro for multiple rows bigproblem Excel Discussion (Misc queries) 6 April 5th 09 09:46 PM
Using Command Button to copy cells Pennington Excel Discussion (Misc queries) 1 April 29th 05 02:30 AM
copy & paste command button RENEE RINEHART Excel Programming 4 April 9th 04 06:10 AM
copy and delete command button Mark Kubicki Excel Programming 0 October 6th 03 08:20 PM


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