View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Making code less column-specific

This assumes a header row for row 1. If you do not have a header row simply
insert a row.

Sub changeallnumbersinselectedcolumn()
Dim mc, lr As Long
Dim row1value As String
mc = ActiveCell.Column
lr = Cells(Rows.Count, mc).End(xlUp).Row
If lr = 1 Then Exit Sub
row1value = Cells(1, mc)
Cells(1, mc) = InputBox("Vary Number By How Much?")
Cells(1, mc).Copy
Range(Cells(2, mc), Cells(lr, mc)).PasteSpecial _
Paste:=xlPasteAll, Operation:=xlAdd
Application.CutCopyMode = False
Cells(1, mc) = row1value
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Colin Hayes" wrote in message
...
In article , Don Guillett
writes
Show your layout or send a sample workbook to my address below with a
clear
explanation and before/after examples.

Don ,

Here's an example :

Before

A B C D

1 132 56 12
2 133 56 13
3 134 56 14
4 135 56 15
5 136 56 16
6 137 56 17
7 138 56 18
8 139 56 19
9 140 56 20
10 141 56 21
11 142 56 22
12 143 56 23
13 144 56 24
14 145 56 25
15 146 56 26



* I need to be able to highlight any complete column , and run the macro.

* The Popup will ask me what number to add or subtract from the cells in
the column I've chosen.

*EG I highlight column B , and run the macro. I enter a figure of -5 and
click OK. Each number in column B is reduced by 5.

* The changes overwrite the original cells , down to the last one in the
column.

* The macro would work on the selected column , whichever it is.

* There is a header cell , so it would operate from Row 2 down.


After

A B C D

1 127 56 12
2 128 56 13
3 129 56 14
4 130 56 15
5 131 56 16
6 132 56 17
7 133 56 18
8 134 56 19
9 135 56 20
10 136 56 21
11 137 56 22
12 138 56 23
13 139 56 24
14 140 56 25
15 141 56 26


* Hope that's a bit clearer now. Outcome shown above.



Best Wishes


Colin