Solved

Shorten VBA to one statement instead of three?

Posted on 2014-10-08
6
97 Views
Last Modified: 2014-10-08
Is there a way to combine Ln2 thru 4?  I do not believe I have to select the sheet tab each time as long as it is active.  I just want to put the value collected for Ln1 in a specific cell location on a specific sheet tab.

    MatlDescValue = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description
    Sheets("BasicData1").Select
    Range("B5").Select
    ActiveCell.FormulaR1C1 = MatlDescValue

Open in new window

0
Comment
Question by:RWayneH
  • 4
  • 2
6 Comments
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368382
Sheets("BasicData1").Range("B5").Select
0
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368385
     MatlDescValue = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description
    Sheets("BasicData1").Range("B5").Select
    ActiveCell.FormulaR1C1 = MatlDescValue

Open in new window

0
 
LVL 25

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40368389
i did not read your question correctly.

now here you go.  to put them all in one line see code below


 Sheets("BasicData1").Range("B5").Value = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description

Open in new window

0
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.

 

Author Comment

by:RWayneH
ID: 40368395
Does it have to select B5?  Could I do something like:
Sheets("BasicData1").Range("B5") = MatlDescValue    ?  I just would like to eliminate lines that are not needed.
0
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368400
the last code i posted, is not selecting anything. it is using the ".Value" Property .

you cannot use Sheets("BasicData1").Range("B5") = MatlDescValue

instead you can use

Sheets("BasicData1").Range("B5").Value = MatlDescValue
0
 

Author Closing Comment

by:RWayneH
ID: 40368424
Yup worked great...   I need to focus on combining lines of code... speeds up the process and makes them easy to read.
THANKS!
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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

16 Experts available now in Live!

Get 1:1 Help Now