Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default search columns, set variable value

I have two questions. First, I want to search down a column. If the first
row is blank, skip to the next, if blank skip to next, so on... I want excel
to stop at the first row that has a value in it, then set that value into a
declared variable. If there's no value within the entire column, then leave
the variable as an empty type value.

That's it... piece of cake for you guys... I can't get the syntax right to
save my life!!

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default search columns, set variable value

This code looks in for the first value in column A below A1 on the active
sheet...

Sub test()
Dim rngFound As Range

Set rngFound = ActiveSheet.Range("A1").End(xlDown)

If rngFound.Row < 65536 Then MsgBox rngFound.Value
End Sub

replace msgbox with "YourVariable = "

HTH

"Robert" wrote:

I have two questions. First, I want to search down a column. If the first
row is blank, skip to the next, if blank skip to next, so on... I want excel
to stop at the first row that has a value in it, then set that value into a
declared variable. If there's no value within the entire column, then leave
the variable as an empty type value.

That's it... piece of cake for you guys... I can't get the syntax right to
save my life!!

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default search columns, set variable value

That would miss A1 if it were populated.

Sub test()
Dim rngFound As Range
if isempty(ActiveSheet.Range("A1")) then
Set rngFound = ActiveSheet.Range("A1").End(xlDown)
else
set rngFound = ActiveSheet.Range("A1")
end if
if Not isempty(rngFound) then
myval = rngFound.Value
End if
End Sub

--
Regards,
Tom Ogilvy



"Jim Thomlinson" wrote in message
...
This code looks in for the first value in column A below A1 on the active
sheet...

Sub test()
Dim rngFound As Range

Set rngFound = ActiveSheet.Range("A1").End(xlDown)

If rngFound.Row < 65536 Then MsgBox rngFound.Value
End Sub

replace msgbox with "YourVariable = "

HTH

"Robert" wrote:

I have two questions. First, I want to search down a column. If the

first
row is blank, skip to the next, if blank skip to next, so on... I want

excel
to stop at the first row that has a value in it, then set that value

into a
declared variable. If there's no value within the entire column, then

leave
the variable as an empty type value.

That's it... piece of cake for you guys... I can't get the syntax right

to
save my life!!

Thanks!



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
Calculating with Variable Search markd951 New Users to Excel 10 December 3rd 09 11:57 AM
Syntax for variable search Tom Ogilvy Excel Programming 3 August 6th 03 06:16 PM
Syntax for variable search brym Excel Programming 0 August 6th 03 05:41 PM
Syntax for variable search brym Excel Programming 2 August 6th 03 05:32 PM
Syntax for variable search Don Guillett[_4_] Excel Programming 0 August 6th 03 04:35 PM


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