Computing.Net > Forums > Office Software > Help with row command in excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with row command in excel

Reply to Message Icon

Name: MarkyMark
Date: September 26, 2008 at 12:11:29 Pacific
OS: XP, excel 2003
CPU/Ram: socket 775, 4 ghz
Comment:

Hello,

I'd like excel to move the number one in column A to a row the user selects with the mouse (or to the active cell is). For instance if user selects C6 the macro would put the numer one in A6 and when user selects another cell in a another row for instance D9 it would "delete" the number one in A6 and move it to A9 and so on...

So far I managed this, but it doesn't get me very long.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("c6").Address Then _
Target.Offset(0, -2).Range("a1") = 1

End Sub

Can someone please help me,

Regards,
Mark



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: September 26, 2008 at 13:08:52 Pacific
Reply:

You're working too hard! ;-)

Putting the 1 in column A of the target row is fairly easy. You don't need to determine what cell was selected. You could use either of these lines:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells(Target.Row, 1) = 1
'or
Range("A" & Target.Row) = 1
End Sub

Deleting the previous 1 might be a little tougher. If there is nothing else in Column A, then you can simply clear the entire column or a specific range before you add the "new" 1. This clears the entire column.

Columns(1).ClearContents
Cells(Target.Row, 1) = 1

However, if you have other data in column A that you need to retain, then you'll need to search for the 1 and delete it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Columns(1)
Set c = .Find(1, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then c.Delete
End With
Range("A" & Target.Row) = 1
End Sub

This assumes that it is the only 1 in column A. If you have other 1's in Column A that you don't want deleted, it gets even more complex.


0

Response Number 2
Name: MarkyMark
Date: September 26, 2008 at 13:26:13 Pacific
Reply:

thanx for your prompt reply. I can manage now! ;)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Outlook 02, freezes sendi... Excel count function



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Help with row command in excel

Need help with IF statement in Exce www.computing.net/answers/office/need-help-with-if-statement-in-exce/5152.html

How to writ a formula in Excel www.computing.net/answers/office/how-to-writ-a-formula-in-excel/311.html

Excel formula references problem www.computing.net/answers/office/excel-formula-references-problem/5265.html