Solved

excel macro

Posted on 2013-01-17
6
148 Views
Last Modified: 2013-01-22
Hello, I am trying to create a macro that will change when the user only uses the drop down and it will populate the row with data from the vlookup. I have the following code but am stuck like braindead. Im learning and could use an experts help! Thanks!



Private Sub Worksheet_Change(ByVal NameBox As Range)
       
      
       Dim c As Range
       Range ("c4:m4")
     'For Each c In Range("c4:m4")
     'If Not IsNumeric(c) Then
     c.ClearContents
  '   Next c
'End If
             Insert_Block
       End Sub


Option Explicit
    Const SUMMARY_COLOR = 48
    Const DETAIL_COLOR = 36

Sub Insert_Block()
   
   
   
        

   With Range("C4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,3,FALSE)"
      .Value = .Value
       End With
      With Range("D4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,4,FALSE)"
      .Value = .Value
       End With
      With Range("E4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,5,FALSE)"
      .Value = .Value
       End With
      With Range("F4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,6,FALSE)"
      .Value = .Value
       End With
      With Range("G4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,7,FALSE)"
      .Value = .Value
       End With
      With Range("H4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,8,FALSE)"
      .Value = .Value
       End With
      With Range("I4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,9,FALSE)"
      .Value = .Value
       End With
      With Range("J4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,10,FALSE)"
      .Value = .Value
       End With
      With Range("K4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,11,FALSE)"
      .Value = .Value
       End With
      With Range("L4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,12,FALSE)"
      .Value = .Value
       End With
      With Range("M4")
      .Formula = "=VLOOKUP( B4,'EXCEPTION % SUMMARY'!$A:$N,13,FALSE)"
      .Value = .Value
    
    End With
   
     
    
End Sub

Open in new window

0
Comment
Question by:jquestion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 38787808
could you pl attach yr excel sheet with macro for fast reply!
0
 

Author Comment

by:jquestion
ID: 38788446
0
 

Author Comment

by:jquestion
ID: 38788571
This is the file Im trying to get to work. any help would be greatly appreciated
TestMacro.xlsm
0
 
LVL 24

Accepted Solution

by:
Steve earned 500 total points
ID: 38803103
OK, attached is a "corrected" version of the code you are trying to accomplish.

There are plenty of alternatives to get the job done.

But this is close to what you were trying to do.
TestMacro.xlsm
0
 

Author Closing Comment

by:jquestion
ID: 38805443
Awesome, Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

717 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