Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default for next loop question

I am using the code below to enter a new column in a worksheet and fill the
new column with a value based on the contents in to different cells. This
works fine.

I would like to enter a vlookup formula in column P each time the code
loops. I dont know how to add the vlookup formula in the loop code

Thanks for any help


Sub subtest1()
Dim rang As Range, lngrow As Long, lngcount As Long, ws As Worksheet
Worksheets("Production").Columns(1).Insert
Set ws = Worksheets("Production")
lngrow = ws.Cells(Rows.Count, "B").End(xlUp).Row
rng = lngrow
For Each rng In Range("A1:A" & lngrow)
rng.Value = rng.Offset(0, 1) & rng.Offset(0, 2)


Next rng
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default for next loop question

Hi,

It would have helped if you told us what you wanted to Vlookup and where but
here's something that may get you started

For Each Rng In Range("A1:A" & lngrow)
Rng.Value = Rng.Offset(0, 1) & Rng.Offset(0, 2)
Rng.Offset(, 15).Formula = "=vlookup(" & Rng.Address & ",J1:K100,2,false)"
Next Rng
End Sub

Mike

"ram" wrote:

I am using the code below to enter a new column in a worksheet and fill the
new column with a value based on the contents in to different cells. This
works fine.

I would like to enter a vlookup formula in column P each time the code
loops. I dont know how to add the vlookup formula in the loop code

Thanks for any help


Sub subtest1()
Dim rang As Range, lngrow As Long, lngcount As Long, ws As Worksheet
Worksheets("Production").Columns(1).Insert
Set ws = Worksheets("Production")
lngrow = ws.Cells(Rows.Count, "B").End(xlUp).Row
rng = lngrow
For Each rng In Range("A1:A" & lngrow)
rng.Value = rng.Offset(0, 1) & rng.Offset(0, 2)


Next rng
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default for next loop question

Edit the VLOOKUP formula to suit.

For Each rng In Range("A1:A" & lngrow)
rng.Value = rng.Offset(0, 1) & rng.Offset(0, 2)
rng.Offset(0, 15).Formula = "=VLOOKUP(G" & rng.Row & ",$A$1:$D$56,3,FALSE)"


Gord Dibben MS Excel MVP

On Fri, 16 Oct 2009 12:02:01 -0700, ram
wrote:

I am using the code below to enter a new column in a worksheet and fill the
new column with a value based on the contents in to different cells. This
works fine.

I would like to enter a vlookup formula in column P each time the code
loops. I don’t know how to add the vlookup formula in the loop code

Thanks for any help


Sub subtest1()
Dim rang As Range, lngrow As Long, lngcount As Long, ws As Worksheet
Worksheets("Production").Columns(1).Insert
Set ws = Worksheets("Production")
lngrow = ws.Cells(Rows.Count, "B").End(xlUp).Row
rng = lngrow
For Each rng In Range("A1:A" & lngrow)
rng.Value = rng.Offset(0, 1) & rng.Offset(0, 2)


Next rng
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default for next loop question

Hi Mike,


I will be looking for the mothly production numbers located on a second
sheet. I think i came accross the vlookup code before.

Thanks for your help

"Mike H" wrote:

Hi,

It would have helped if you told us what you wanted to Vlookup and where but
here's something that may get you started

For Each Rng In Range("A1:A" & lngrow)
Rng.Value = Rng.Offset(0, 1) & Rng.Offset(0, 2)
Rng.Offset(, 15).Formula = "=vlookup(" & Rng.Address & ",J1:K100,2,false)"
Next Rng
End Sub

Mike

"ram" wrote:

I am using the code below to enter a new column in a worksheet and fill the
new column with a value based on the contents in to different cells. This
works fine.

I would like to enter a vlookup formula in column P each time the code
loops. I dont know how to add the vlookup formula in the loop code

Thanks for any help


Sub subtest1()
Dim rang As Range, lngrow As Long, lngcount As Long, ws As Worksheet
Worksheets("Production").Columns(1).Insert
Set ws = Worksheets("Production")
lngrow = ws.Cells(Rows.Count, "B").End(xlUp).Row
rng = lngrow
For Each rng In Range("A1:A" & lngrow)
rng.Value = rng.Offset(0, 1) & rng.Offset(0, 2)


Next rng
End Sub

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
Loop Do Until question Barry McConnell Excel Programming 6 July 9th 08 03:13 PM
Loop question aelewis Excel Discussion (Misc queries) 2 October 24th 07 08:12 PM
Loop question N.F[_2_] Excel Discussion (Misc queries) 0 July 12th 07 08:02 PM
loop question choice[_2_] Excel Programming 7 October 30th 05 05:41 AM
loop question dabith Excel Programming 6 June 13th 04 05:28 PM


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