Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default VLOOKUP in a Macro

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default VLOOKUP in a Macro

Countif is probably a better choice than Vlookup. countif is faster for one
thing and a little easier to implement

for I = 170 to 182
IF Application.Countif(DayNr,I)<0 THEN
something
ENDIF
Next

HTH

"Peter Hesselager" wrote:

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default VLOOKUP in a Macro

You're just the guy !
I only had to use the Range-command to avoid a Type Mismatch - like this

If Application.CountIf(Range("DagNr"), I) < 0 Then

-eeh, now can you also tell me how to go to the A column on the actual Row ?
I Have tried
Selection.End(xlToLeft).Select
but some cells in the row may be empty - so it's not a sure thing


"Jim Thomlinson" wrote:

Countif is probably a better choice than Vlookup. countif is faster for one
thing and a little easier to implement

for I = 170 to 182
IF Application.Countif(DayNr,I)<0 THEN
something
ENDIF
Next

HTH

"Peter Hesselager" wrote:

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default VLOOKUP in a Macro

Sorry I did not know if DagNr was a range object or a named range. There are
a couple of possible solutions to get the A Column. Since I don't know if
Selection is a single Cell or a range of cells and I don't know if you want
to select the A Cells I will give you the full blown solution...

dim rng as range

set rng = intersect(activesheet.range("A:A"), selection.entirecolumn)
'You can now just use rng like any range of cells
rng.select

HTH

"Peter Hesselager" wrote:

You're just the guy !
I only had to use the Range-command to avoid a Type Mismatch - like this

If Application.CountIf(Range("DagNr"), I) < 0 Then

-eeh, now can you also tell me how to go to the A column on the actual Row ?
I Have tried
Selection.End(xlToLeft).Select
but some cells in the row may be empty - so it's not a sure thing


"Jim Thomlinson" wrote:

Countif is probably a better choice than Vlookup. countif is faster for one
thing and a little easier to implement

for I = 170 to 182
IF Application.Countif(DayNr,I)<0 THEN
something
ENDIF
Next

HTH

"Peter Hesselager" wrote:

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default VLOOKUP in a Macro

Oops... change

set rng = intersect(activesheet.range("A:A"), selection.entirecolumn)
to
set rng = intersect(activesheet.range("A:A"), selection.entirerow)

Dopey me...


"Jim Thomlinson" wrote:

Sorry I did not know if DagNr was a range object or a named range. There are
a couple of possible solutions to get the A Column. Since I don't know if
Selection is a single Cell or a range of cells and I don't know if you want
to select the A Cells I will give you the full blown solution...

dim rng as range

set rng = intersect(activesheet.range("A:A"), selection.entirecolumn)
'You can now just use rng like any range of cells
rng.select

HTH

"Peter Hesselager" wrote:

You're just the guy !
I only had to use the Range-command to avoid a Type Mismatch - like this

If Application.CountIf(Range("DagNr"), I) < 0 Then

-eeh, now can you also tell me how to go to the A column on the actual Row ?
I Have tried
Selection.End(xlToLeft).Select
but some cells in the row may be empty - so it's not a sure thing


"Jim Thomlinson" wrote:

Countif is probably a better choice than Vlookup. countif is faster for one
thing and a little easier to implement

for I = 170 to 182
IF Application.Countif(DayNr,I)<0 THEN
something
ENDIF
Next

HTH

"Peter Hesselager" wrote:

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Selecting the leftmost cell on a row

Hi Jim !
I only got to this issue now ( the CountIf works just fine now).
Sorry, that I wasn't more detailed in my former question
I have to go to the A cell on the actual row.
The user may stand on any cell on a ROW, when he activates the Macro.
So - to have a well defined activeCell, from which I can reach out with
Offset commands - I want to activate the very leftmost cell on the row.
The macro only deals with values on the actual row -
anyway - i'll look into it now

"Jim Thomlinson" wrote:

Oops... change

set rng = intersect(activesheet.range("A:A"), selection.entirecolumn)
to
set rng = intersect(activesheet.range("A:A"), selection.entirerow)

Dopey me...


"Jim Thomlinson" wrote:

Sorry I did not know if DagNr was a range object or a named range. There are
a couple of possible solutions to get the A Column. Since I don't know if
Selection is a single Cell or a range of cells and I don't know if you want
to select the A Cells I will give you the full blown solution...

dim rng as range

set rng = intersect(activesheet.range("A:A"), selection.entirecolumn)
'You can now just use rng like any range of cells
rng.select

HTH

"Peter Hesselager" wrote:

You're just the guy !
I only had to use the Range-command to avoid a Type Mismatch - like this

If Application.CountIf(Range("DagNr"), I) < 0 Then

-eeh, now can you also tell me how to go to the A column on the actual Row ?
I Have tried
Selection.End(xlToLeft).Select
but some cells in the row may be empty - so it's not a sure thing


"Jim Thomlinson" wrote:

Countif is probably a better choice than Vlookup. countif is faster for one
thing and a little easier to implement

for I = 170 to 182
IF Application.Countif(DayNr,I)<0 THEN
something
ENDIF
Next

HTH

"Peter Hesselager" wrote:

I can't make the Data_value work

for I = 170 to 182
IF I = VLOOKUP(I, DayNr,1) THEN
something
ENDIF
Next

I = actual daynumber
DayNr is a range of Working day No.

If I substitute "I" with a value ( say 170), it works OK.
The goal is to decide, whether I is a working day or not.

How should it be written ?


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
Macro - Vlookup orquidea Excel Discussion (Misc queries) 6 May 14th 08 04:42 PM
vlookup macro MikeD1224 New Users to Excel 1 June 16th 07 04:37 AM
VLOOKUP in a macro?? chip_pyp Excel Discussion (Misc queries) 1 March 27th 06 09:40 PM
VLOOKUP MACRO JOHN YOUNG Excel Programming 2 July 23rd 04 10:21 PM
Need a macro to do what this VLOOKUP does Tim Excel Programming 5 February 12th 04 04:41 PM


All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"