Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Find Cell Value and Activate

I got most of the below code from this newgroup, I have modified it slightly, my goal is to have it look up a value in column G, in this case the variable "Month4", if that value exists then assign the row number to the variable PasteRange, otherwise if the value doesn't exist, then find the last row with data, add one, and assign that row value to the variable PasteRange

Set rng = Range(Range("G2"), Range("G65000").End(xlUp)
For Each c In rn
If c = Month4 The
PasteRange = ActiveCell.Ro
Exit Fo
Els
End I
Next
If PasteRange = 0 The
PasteRange = Cells(Rows.Count, "A").End(xlUp).Row +

Els
End I

When I run it, it finds the value if it exists but then just assigns the first row to the variable PasteRange. I am not sure how to make this code select the row that it found the value in, and then assign that row to the variable PasteRange

Any help on this would be greatly appreciated

Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Find Cell Value and Activate

Set rng = Range(Range("G2"), Range("G" & Rows.Count).End(xlUp))
For Each c In rng
If c.Value = Month4 Then
PasteRange = c.Row
Exit For
End If
Next c
If PasteRange = 0 Then
PasteRange = Cells(Rows.Count, "A").End(xlUp).Row + 1
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"James Stephens" wrote in message
...
I got most of the below code from this newgroup, I have modified it

slightly, my goal is to have it look up a value in column G, in this case
the variable "Month4", if that value exists then assign the row number to
the variable PasteRange, otherwise if the value doesn't exist, then find the
last row with data, add one, and assign that row value to the variable
PasteRange.


Set rng = Range(Range("G2"), Range("G65000").End(xlUp))
For Each c In rng
If c = Month4 Then
PasteRange = ActiveCell.Row
Exit For
Else
End If
Next c
If PasteRange = 0 Then
PasteRange = Cells(Rows.Count, "A").End(xlUp).Row + 1

Else
End If

When I run it, it finds the value if it exists but then just assigns the

first row to the variable PasteRange. I am not sure how to make this code
select the row that it found the value in, and then assign that row to the
variable PasteRange.

Any help on this would be greatly appreciated.

Jim



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
activate cell varun Excel Worksheet Functions 1 February 5th 09 08:18 AM
how to activate macro from cell artzuka Excel Discussion (Misc queries) 2 January 6th 09 09:12 PM
Activate Cell Brett Excel Discussion (Misc queries) 2 March 29th 05 06:20 PM
How do I activate the trial exel 2003 program if it does't find c. Dolores Dueck New Users to Excel 1 January 3rd 05 02:19 AM
Using a Macro to find a value in a range and activate it Travis Excel Programming 4 April 8th 04 08:49 PM


All times are GMT +1. The time now is 06:04 AM.

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"