ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VB problem (https://www.excelbanter.com/excel-discussion-misc-queries/181847-vbulletin-problem.html)

FiluDlidu

VB problem
 
I'm sure there's a way to do it, but I'm just starting to play with VB and I
don't know too much yet about it (this discussion group being filled with
kind people who seem to enjoy puzzles, I take a chance :-)

If I select a cell or range within column D, for every EMPTY cell of the
selected range whose equivalent in row M is a NUMBER, I want the number in
question to be copied over to the empty cell.

I'd like to kindly thank any who will spend even fruitless time on this
problem and to apologize to whoever might have conceived frustration at me
while doing so.

Feelu

Tom Hutchins

VB problem
 
Put this SelectionChange event code in the code page for the worksheet where
you want this to work:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
If Intersect(Target, Columns("D")) Is Nothing Then Exit Sub
For Each c In Target
If Len(c.Value) = 0 And IsNumeric(c.Offset(0, 9)) Then
c.Value = c.Offset(0, 9).Value
End If
Next c
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Hope this helps,

Hutch

"FiluDlidu" wrote:

I'm sure there's a way to do it, but I'm just starting to play with VB and I
don't know too much yet about it (this discussion group being filled with
kind people who seem to enjoy puzzles, I take a chance :-)

If I select a cell or range within column D, for every EMPTY cell of the
selected range whose equivalent in row M is a NUMBER, I want the number in
question to be copied over to the empty cell.

I'd like to kindly thank any who will spend even fruitless time on this
problem and to apologize to whoever might have conceived frustration at me
while doing so.

Feelu


FiluDlidu

VB problem
 
That worked just like a charm.

Thanks for taking the time to answer and also for the link you provided in
your message. That was very kind.

Feelu

"Tom Hutchins" wrote:

Put this SelectionChange event code in the code page for the worksheet where
you want this to work:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
If Intersect(Target, Columns("D")) Is Nothing Then Exit Sub
For Each c In Target
If Len(c.Value) = 0 And IsNumeric(c.Offset(0, 9)) Then
c.Value = c.Offset(0, 9).Value
End If
Next c
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Hope this helps,

Hutch

"FiluDlidu" wrote:

I'm sure there's a way to do it, but I'm just starting to play with VB and I
don't know too much yet about it (this discussion group being filled with
kind people who seem to enjoy puzzles, I take a chance :-)

If I select a cell or range within column D, for every EMPTY cell of the
selected range whose equivalent in row M is a NUMBER, I want the number in
question to be copied over to the empty cell.

I'd like to kindly thank any who will spend even fruitless time on this
problem and to apologize to whoever might have conceived frustration at me
while doing so.

Feelu



All times are GMT +1. The time now is 02:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com