Solved

VBA Code to find name and populate cell

Posted on 2011-09-08
4
205 Views
Last Modified: 2012-05-12
Using xl2007

What I am looking for the code to do:

(i) would be the row number as we loop through

If the Cell in Column E, Row (i) = "RB"
then find the first cell ABOVE it in Column E that Says "C".  
The value from column D on the Row containing C needs to go into Column I on row (i)
The value from Column F on the Row containing C needs to go into Column J row (i)

If the Cell in Column E, Row (i) does not equal "RB" then move on to the next row

Any assistance is greatly appreciated!

Thanks, Brandon
0
Comment
Question by:KnutsonBM
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Bill Prew
ID: 36502779
So, are you looking for a function, that will be called passing it "i"?

~bp
0
 
LVL 6

Author Comment

by:KnutsonBM
ID: 36502794
no, no functions, just some simple vba code to loop through the dataset and populate Columns I and J
0
 
LVL 6

Author Comment

by:KnutsonBM
ID: 36502813
DOH, i figured it out, sorry to bother yall:

Sub FindResp()

Dim Z As Integer
Dim i As Integer


i = 2


Do Until Cells(i, "A").Value = ""

    If Cells(i, "E").Value = "ROUTE BACK" Then
   
        Z = i
       
            Do Until Cells(Z, "E").Value = "COMPLETE"
           
                Z = Z - 1
               
            Loop
           
            Cells(i, "I").Value = Cells(Z, "D").Value
            Cells(i, "J").Value = Cells(Z, "F").Value
           
    Else
    End If
   
    i = i + 1
   
Loop
               
           
End Sub

if anybody has suggestions for better coding i would gladly take them.........

-Brandon
0
 
LVL 12

Accepted Solution

by:
josika earned 500 total points
ID: 36502817
Try this:

Set oExcel = CreateObject("Excel.Application")
Set oWorkBook = oExcel.Workbooks.Open ("c:\Sheet.xlsx")
Do Until oExcel.Cells(i,"a").Value = ""
	If UCase(oExcel.Cells(i,"e").Value) = "RB" Then
		x = i - 1
		Do Until x = 0
			If UCase(oExcel.Cells(x,"e").Value) = "C" Then
				oExcel.Cells(i,"i").Value = oExcel.Cells(x,"d").Value
				oExcel.Cells(i,"j").Value = oExcel.Cells(x,"f").Value
				Exit Do
			End If
			x = x - 1
		Loop
	End If
	i = i + 1
Loop

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now